예제 #1
0
def describe(store, uri, outputGraph):
    query = '''PREFIX hint: <http://www.bigdata.com/queryHints#>
describe %s where { hint:Query hint:describeMode "CBD". }'''
    g = ConjunctiveGraph(store)
    try:
        outputGraph += g.query(query % uri.n3())
    except:
        outputGraph += g.query("select ?s ?p ?o where { ?s ?p ?o}", initBindings={"s":uri})
예제 #2
0
def describe(store, uri, outputGraph):
    query = '''PREFIX hint: <http://www.bigdata.com/queryHints#>
describe %s where { hint:Query hint:describeMode "CBD". }'''
    g = ConjunctiveGraph(store)
    try:
        outputGraph += g.query(query % uri.n3())
    except:
        outputGraph += g.query("construct {%s ?p ?o} where { %s ?p ?o}"% (uri.n3(),uri.n3()))
예제 #3
0
    def list(self):
        query = '''prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix dc: <http://purl.org/dc/terms/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix prov: <http://www.w3.org/ns/prov#>
construct {
    ?s a %s ;
       skos:prefLabel ?prefLabel;
       rdfs:label ?label;
       dc:title ?title;
       dc:identifier ?identifier;
       rdfs:seeAlso ?seeAlso;
       owl:sameAs ?sameAs;
       prov:alternateOf ?altOf;
       prov:specializationOf ?specOf.
} where {
    ?s a %s .
    optional {?s skos:prefLabel ?prefLabel}
    optional {?s rdfs:label ?label}
    optional {?s dc:title ?title}
    optional {?s dc:identifier ?identifier}
    optional {?s rdfs:seeAlso ?seeAlso}
    optional {?s owl:sameAs ?sameAs}
    optional {?s prov:alternateOf ?altOf}
    optional {?s prov:specializationOf ?specOf}
}'''
        g = ConjunctiveGraph(self.store)
        return g.query(query % (self.cl.n3(), self.cl.n3()))
예제 #4
0
    def _top_classes(self):

        import rdflib.plugin
        from rdflib.store import Store
        from rdflib.parser import Parser
        from rdflib.serializer import Serializer
        from rdflib.query import ResultParser, ResultSerializer, Processor, Result, UpdateProcessor
        from rdflib.exceptions import Error
        rdflib.plugin.register('sparql', Result,
                               'rdflib.plugins.sparql.processor',
                               'SPARQLResult')
        rdflib.plugin.register('sparql', Processor,
                               'rdflib.plugins.sparql.processor',
                               'SPARQLProcessor')
        rdflib.plugin.register('sparql', UpdateProcessor,
                               'rdflib.plugins.sparql.processor',
                               'SPARQLUpdateProcessor')

        retr_query = '''
construct {
  ?subClass rdfs:subClassOf ?id;
            a ?type;
            rdfs:label ?sclabel.
  ?id rdfs:label ?label;
      a ?idtype.
} where {
    {
       ?subClass rdfs:subClassOf ?id.
    }
    optional {
       ?subClass a ?type.
    }
    optional {
        ?subClass rdfs:label ?sclabel.
    }
    optional {
        ?id rdfs:label ?label
    }
    optional {
        ?id a ?idtype.
    }
}'''
        g = self.db.query(retr_query).graph

        #print list(g[::self.NS.sio.object])

        query = '''

select distinct ?id where {
    {
       ?subClass rdfs:subClassOf ?id.
    }
    ?id rdfs:label ?label.
    optional {
        ?id rdfs:subClassOf ?superClass.
    }
    FILTER (!bound(?superClass))
    FILTER (isURI(?id))
} order by ?label'''
        return [g.resource(i[0]) for i in g.query(query)]
예제 #5
0
 def count(self):
     g = ConjunctiveGraph(self.store)
     query = '''select (count(?s) as ?count) where {?s a %s}'''
     return list(g.query(query % self.cl.n3()))[0][0].value