Search code examples
graphdb

GraphDB: use similarity search with embedded repository


I have been using GraphDB's (version 9.2) similarity search from the workbench. Now I also want to use this feature for an embedded repository using graphdb-free-runtime 9.2.1. However I have no clue how this feature can be used from the APIs provided by the runtime. My questions are:

Any hints or pointers are welcome.


Solution

  • You could add similarity plugin runtime, setting following "graphdb.extra.plugins" property to directory where similarity-plugin (you could find such into GDB instance -> dist/lib/plugins) is located , or:

    1. -Dgraphdb.extra.plugins=directory
    2. System.setProperty("graphdb.extra.plugins", "directory");

    You may create index programmatically using SPARQL or:

    to create similarity text index "allNews" execute following update:

    PREFIX : <http://www.ontotext.com/graphdb/similarity/>
    PREFIX inst: <http://www.ontotext.com/graphdb/similarity/instance/>
    PREFIX pred: <http://www.ontotext.com/graphdb/similarity/psi/>
    insert {
        inst:allNews :createIndex "-termweight idf" ;
            :analyzer "org.apache.lucene.analysis.en.EnglishAnalyzer" ;
            :documentID ?documentID .
            ?documentID :documentText ?documentText .
    } where {
        SELECT ?documentID ?documentText {
            ?documentID ?p ?documentText .
            filter(isLiteral(?documentText))
        }
    }
    

    to delete index "allNews" execute following update:

    PREFIX :<http://www.ontotext.com/graphdb/similarity/>
    PREFIX inst:<http://www.ontotext.com/graphdb/similarity/instance/>
    
    insert { inst:allNews :deleteIndex '' } where {}
    

    to rebuild index "allNews":

    PREFIX :<http://www.ontotext.com/graphdb/similarity/>
    PREFIX inst:<http://www.ontotext.com/graphdb/similarity/instance/>
    
    insert { inst:allNews :rebuildIndex '' } where {}
    

    followed by the create query!

    to list all created indexes, execute following query:

    PREFIX :<http://www.ontotext.com/graphdb/similarity/>
    PREFIX inst:<http://www.ontotext.com/graphdb/similarity/instance/>
    
    select ?index ?status ?type
    where {
      ?index :status ?status .
      ?index :type ?type .
    }