DLR-SC / corpus-annotation-graph-builder

Corpus Annotation Graph builder (CAG) is an architectural framework that employs the build-and-annotate pattern for creating a graph.
MIT License
10 stars 1 forks source link

[Support] Error creating View #9

Closed muelldlr closed 1 year ago

muelldlr commented 1 year ago

I'm trying to create a View and got the following error:

grafik

Code:

analyzer_ngram = ArangoAnalyzer("fuzzy_search_bigram")
        analyzer_ngram.set_edge_ngrams(max=3)
        analyzer_ngram.type = ArangoAnalyzer._TYPE_NGRAM
        analyzer_ngram.set_features()

        analyzer_ngram.create(self.arango_db)

        analyzer_token = ArangoAnalyzer("en_tokenizer")
        analyzer_token.set_stopwords(include_default=False)
        analyzer_token.stemming = True
        analyzer_token.accent = False
        analyzer_token.type = ArangoAnalyzer._TYPE_TEXT
        analyzer_token.set_features()

        analyzer_token.create(self.arango_db)

        # Create Link - a view can hvae 0 to * links
        link = Link(name="Publication")  # Name of a collection in the database
        linkAnalyzers = AnalyzerList(
            ["fuzzy_search_bigram", "en_tokenizer"])
        link.analyzers = linkAnalyzers

        # A link can have 0..* fields
        # text_en is a predifined analyzer from arango
        title_field = Field("title", AnalyzerList(
            ["fuzzy_search_bigram", "en_tokenizer"]))
        abstract_field = Field("abstract", AnalyzerList(
            ["fuzzy_search_bigram", "en_tokenizer"]))
        title_emb_field = Field("title_emb")
        abstract_emb_field = Field("abstract_emb")
        id_field = Field("_id")
        display_field = Field("display_name", AnalyzerList(
            ["fuzzy_search_bigram", "en_tokenizer"]))
        #
        # "title_emb": {},
        # "title": {},
        # "display_name": {},
        # "abstract_emb": {},
        # "abstract": {},
        # "_id": {}
        link.add_field(title_field)
        link.add_field(abstract_field)
        link.add_field(title_emb_field)
        link.add_field(abstract_emb_field)
        link.add_field(id_field)
        link.add_field(display_field)
        # create view
        view = View('publications_view',
                    view_type="arangosearch")
        # add the link (can have 0 or 1 link)
        view.add_link(link)

        # can have 0..* primary sort
        view.add_primary_sort("title", asc=False)
        view.add_stored_value(["title"], compression="lz4")
        try:
            view.create(self.arango_db)
        except Exception as e:
            print("Error creating view, please delete the one on DB?", e)
            raise e
roxanneelbaff commented 1 year ago

The View fields should use the you probably used from cag.graph_elements.nodes import Field instead of cag.view_wrapper.link.Field. closing issue

muelldlr commented 1 year ago

Resolved: The class Field as here imported is wrong! Changed to from cag.view_wrapper.link import Link, Field as FieldView and replace Field(... with ViewField