1.3.6 • Published 3 years ago

logicmodule v1.3.6

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

code at https://gitlab.fel.cvut.cz/svacefil/logicmodule

Logic module

Part of a semantic faceted search project. The logic module’s responsibility is taking facet data, parsing them into a SPARQL query, and returning data from the endpoint.

To run this logic module, you first need to define facets and contrains

let facets = {
    pojem: { //text facet
        facetId: 'pojem',
        facetType: 'text',
        predicate: 'http://www.w3.org/2004/02/skos/core#prefLabel',
        name: 'Pojem',
    },
    glosar: { //basic select facet
        facetId: 'glosar',
        facetType: 'select',
        predicate: 'http://www.w3.org/2004/02/skos/core#inScheme',
        name: 'Glosář',
    },
    typ: { //basic select facet
        facetId: 'typ',
        facetType: 'select',
        predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
        name: 'Typ',
    }
}
let constrains = {
    concept: {
        constraintId: 'concept',
        predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
        object: 'http://www.w3.org/2004/02/skos/core#Concept'
    }
}

text facets will show as a text input and select facet will show as select options

let resultQueryTemplate = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
    "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> \n" +
    "PREFIX zs: <https://slovník.gov.cz/základní/pojem/> \n" +
    "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> \n" +
    "\n" +
    "SELECT DISTINCT * WHERE \n" +
    "{   \n" +
    "    {\n" +
    "        <RESULT_SET>\n" +
    "    } \n" +
    "     \n" +
    "    FILTER(BOUND(?id))    \n" +
    "    ?id a skos:Concept .  \n" +
    "    OPTIONAL \n" +
    "    {    \n" +
    "        ?id skos:prefLabel ?nazev .    \n" +
    "        FILTER(lang(?nazev)=\"cs\")  \n" +
    "    }  \n" +
    "    OPTIONAL {    \n" +
    "        ?id skos:definition ?definice .    \n" +
    "        FILTER(lang(?definice)=\"cs\")  \n" +
    "    }  \n" +
    "    OPTIONAL {    \n" +
    "        ?id rdfs:subClassOf ?nadtyp__id .    \n" +
    "        OPTIONAL {\n" +
    "            ?nadtyp__id skos:prefLabel ?nadtyp__nazev .    \n" +
    "            FILTER(lang(?nadtyp__nazev) = \"cs\") \n" +
    "        }   \n" +
    "        FILTER(?nadtyp__id not in (skos:Concept,owl:Class,owl:NamedIndividual,owl:ObjectProperty,owl:DataProperty,owl:AnnotationProperty)) \n" +
    "        FILTER(isIri(?nadtyp__id))   \n" +
    "    }  \n" +
    "    OPTIONAL {    \n" +
    "        ?id a ?typ__id .    \n" +
    "        OPTIONAL \n" +
    "        {\n" +
    "            ?typ__id skos:prefLabel ?typ__nazev .    \n" +
    "            FILTER(lang(?typ__nazev) = \"cs\") \n" +
    "        }   \n" +
    "        FILTER(?typ__id not in (skos:Concept,owl:Class,owl:NamedIndividual,owl:ObjectProperty,owl:DataProperty,owl:AnnotationProperty)) \n" +
    "        FILTER(isIri(?nadtyp__id))  \n" +
    "        }  \n" +
    "        OPTIONAL { \n" +
    "            ?typvlastnosti__id rdfs:subClassOf ?r2 .  \n" +
    "            ?r2 (owl:allValuesFrom/(owl:unionOf/rdf:rest*/rdf:first)?) ?id .  \n" +
    "            ?r2 owl:onProperty zs:je-vlastností .          \n" +
    "            OPTIONAL \n" +
    "            {\n" +
    "                ?typvlastnosti__id skos:prefLabel ?typvlastnosti__nazev . FILTER(lang(?typvlastnosti__nazev) = \"cs\") \n" +
    "            }   \n" +
    "        }  \n" +
    "        OPTIONAL \n" +
    "        { \n" +
    "            ?typvztahu__id rdfs:subClassOf ?r1.  \n" +
    "            ?r1 owl:onProperty zs:má-vztažený-prvek-1 .  \n" +
    "            ?r1 (owl:allValuesFrom/(owl:unionOf/rdf:rest*/rdf:first)?) ?id .           \n" +
    "            OPTIONAL \n" +
    "            { \n" +
    "                ?typvztahu__id skos:prefLabel ?typvztahu__nazev . FILTER(lang(?typvztahu__nazev) = \"cs\") \n" +
    "            }   \n" +
    "        }   \n" +
    "        OPTIONAL \n" +
    "        {    \n" +
    "            ?id skos:inScheme ?glosar__id .     \n" +
    "            OPTIONAL { ?glosar__id rdfs:label ?glosar__nazev .     \n" +
    "            FILTER(lang(?glosar__nazev)=\"cs\")}  \n" +
    "        } \n" +
    "}"

A query that must return id and optionally other columns. Also, it has to have a placeholder string called '<RESULT_SET'> used to filter results by the logicModule.

let selectQueryTemplate = 'SELECT DISTINCT ?cnt ?facet_text ?result WHERE' +
    '{' +
    '  {' +
    '    {' +
    '      <RESULT_SET0>' +
    '    }' +
    '  BIND("" AS ?result)' +
    '  BIND("-- No Selection --" AS ?facet_text)}' +
    '  UNION' +
    '  {' +
    '    SELECT DISTINCT ?cnt ?result ?facet_text WHERE' +
    '    {' +
    '      {' +
    '        <RESULT_SET1>' +
    '      }' +
    '      FILTER(BOUND(?result))' +
    '      BIND(COALESCE(?result, <http://ldf.fi/NONEXISTENT_URI>) AS ?labelValue)' +
    'OPTIONAL ' +
    '{ ' +
    '   ?result <http://www.w3.org/2004/02/skos/core#prefLabel> ' +
    '?enPref . FILTER(langMatches(lang(?enPref), "en")) . } ' +
    'OPTIONAL{ ?result <http://www.w3.org/2000/01/rdf-schema#label> ' +
    '?enLabel . FILTER(langMatches(lang(?enLabel), "en")) . } ' +
    'OPTIONAL { ?result <http://www.w3.org/2004/02/skos/core#prefLabel> ' +
    '?prefLabel . FILTER(langMatches(lang(?prefLabel), "")) . } ' +
    'OPTIONAL { ?result <http://www.w3.org/2000/01/rdf-schema#label> ' +
    '?label . FILTER(langMatches(lang(?label), "")) . } ' +
    'BIND(COALESCE(?enPref, ?enLabel, ?prefLabel, ?label, "undefined label") AS ?facet_text) ' +
    '    } LIMIT 10000' +
    '  }' +
    '}'

A query that must return in each row three columns cnt, facet_text and result. Count being number of returned values, facet_text being the displayed label, and result being the select option value. Also, it has to have two placeholder strings, one searching for the overall result count, another one showing the number of results in each facet value. These strings are called <RESULT_SET0> and <RESULT_SET1>.

Also, you need to setup an endpoint url where the query will be sent.

endpointUrl = 'https://xn--slovnk-7va.gov.cz/sparql'

Finally, you can insert all of these values into the config

let logicConfig = {
    facets : facets,
    endpointUrl : 'https://xn--slovnk-7va.gov.cz/sparql',
    resultQueryTemplate: resultQueryTemplate,
    constrains: constrains,
    selectQueryTemplate : selectQueryTemplate
};

and create the logicModule object

let logicModule = new LogicModule(logicConfig)

now that you have the object logicModule, you can use in combination with any implemented visualmodule, regardless of the visual platform.

Go to https://gitlab.fel.cvut.cz/svacefil/bcproject to see the logic module being used to create a Semantic Vocubulary demo.

1.3.6

3 years ago

1.3.5

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago