Exemplo n.º 1
0
Arquivo: query.py Projeto: t00m/Vazaar
    def get_tags(self, rid):
        select = ("?tag")
        where = GraphPattern([
            (URIRef(rid), NAO['hasTag'], "?tag"),
        ])
        sparqlGrph = SPARQLGraph(self.graph)
        tags = Query.query(sparqlGrph, select, where, initialBindings=None)

        return tags
Exemplo n.º 2
0
Arquivo: query.py Projeto: t00m/Vazaar
 def get_property(self, rid, prop, graph=None):
     if not graph:
         select = ("?object")
         where = GraphPattern([
             (URIRef(rid), URIRef(prop), "?object"),
         ])
         sparqlGrph = SPARQLGraph(self.graph)
         obj = Query.query(sparqlGrph, select, where, initialBindings=None)
     else:
         select = ("?object")
         where = GraphPattern([
             (URIRef(rid), URIRef(prop), "?object"),
         ])
         sparqlGrph = SPARQLGraph(graph)
         obj = Query.query(sparqlGrph, select, where, initialBindings=None)
     try:
         return obj
     except Exception:
         return []
Exemplo n.º 3
0
Arquivo: query.py Projeto: t00m/Vazaar
    def resource_is_collection(self, rid):
        select = ("?res")
        where = GraphPattern([
            (URIRef(rid), RDF.type, PIMO['Collection']),
            (URIRef(rid), NIE['hasLogicalPart'], "?res"),
        ])
        sparqlGrph = SPARQLGraph(self.graph)
        resources = Query.query(sparqlGrph, select, where, initialBindings=None)

        return list(resources)
Exemplo n.º 4
0
Arquivo: query.py Projeto: t00m/Vazaar
 def get_url_from_resource(self, rid):
     select = ("?object")
     where = GraphPattern([
         (URIRef(rid), RDF['type'], "?object")
     ])
     sparqlGrph = SPARQLGraph(self.graph)
     res = Query.query(sparqlGrph, select, where, initialBindings=None)
     try:
         return str(res[0])
     except Exception:
         return None
Exemplo n.º 5
0
Arquivo: query.py Projeto: t00m/Vazaar
 def collections_linked_to_resource(self, rid):
     select = ("?col")
     where = GraphPattern([
         ("?col", NIE['hasLogicalPart'], URIRef(rid))
     ])
     sparqlGrph = SPARQLGraph(self.graph)
     res = Query.query(sparqlGrph, select, where, initialBindings=None)
     try:
         return res
     except  Exception:
         return None
Exemplo n.º 6
0
Arquivo: query.py Projeto: t00m/Vazaar
    def get_property_list(self, rid, prop):
        select = ("?object")
        where = GraphPattern([
            (URIRef(rid), URIRef(prop), "?object"),
        ])
        sparqlGrph = SPARQLGraph(self.graph)
        obj = Query.query(sparqlGrph, select, where, initialBindings=None)

        try:
            return obj
        except Exception, error:
            return error
Exemplo n.º 7
0
Arquivo: query.py Projeto: t00m/Vazaar
    def get_annotations(self, rid):
        select = ("?aid")
        where = GraphPattern([
            (URIRef(rid), URIRef(NAO['annotation']), "?aid"),
            ("?aid", URIRef(NAO['created']), "?date"),
        ])
        orderedBy    = ("?date")
        orderAscend = False
        sparqlGrph = SPARQLGraph(self.graph)
        resultObject = Query.queryObject(graph=sparqlGrph, patterns=where, optionalPatterns=[], initialBindings=None)
        result       = resultObject.select(select,distinct=True,orderBy=orderedBy,orderAscend=False)

        return result
Exemplo n.º 8
0
Arquivo: query.py Projeto: t00m/Vazaar
    def get_resources_by_extension(self, ext=""):
        select = ("?id", "?type", "?title")
        where = GraphPattern([
            ("?id", RDF.type, "?type"),
            ("?id", NIE['title'], "?title"),
            ("?id", NFO['mimetype'], "?type"),
            ("?id", NFO['extension'], Literal(ext)),
            ("?id", NFO['scheme'], Literal('file'))
        ])
        sparqlGrph = SPARQLGraph(self.graph)
        resources = Query.query(sparqlGrph, select, where, initialBindings=None)

        return resources
Exemplo n.º 9
0
Arquivo: query.py Projeto: t00m/Vazaar
    def get_resources_by_property_value(self, predicate, value):
        ns, qname = predicate.split(':')
        #~ print ns, qname
        prop = URIRef(NSBINDINGS[ns][qname])
        if ns == 'rdf':
            value = URIRef(value)
        else:
            value = Literal(value)

        select = ("?id")
        where = GraphPattern([
            ("?id", prop, value)
        ])

        sparqlGrph = SPARQLGraph(self.graph)
        resources = Query.query(sparqlGrph, select, where, initialBindings=None)

        return resources