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
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 []
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)
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
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
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
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
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