예제 #1
0
파일: query.py 프로젝트: 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
예제 #2
0
파일: query.py 프로젝트: 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 []
예제 #3
0
파일: query.py 프로젝트: 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)
예제 #4
0
파일: query.py 프로젝트: 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
예제 #5
0
파일: query.py 프로젝트: 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
예제 #6
0
파일: query.py 프로젝트: 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
예제 #7
0
파일: query.py 프로젝트: 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
예제 #8
0
파일: query.py 프로젝트: 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