def load(self): for ident in GraphObjectQuerier(self, self.rdf)(): types = set() for rdf_type in self.rdf.objects(ident, R.RDF['type']): types.add(rdf_type) the_type = get_most_specific_rdf_type(types) yield oid(ident, the_type)
def get(self): if self.rdf is None: return () results = None owner = self.owner if owner.defined: self._ensure_fresh_po_cache() results = set() for pred, obj in owner.po_cache.cache: if pred == self.link: results.add(obj) else: v = Variable("var" + str(id(self))) self._insert_value(v) def _zomifier(rdf_type): if rdf_type and getattr(self, 'value_rdf_type', None) == rdf_type: return SubClassModifier(rdf_type) g = ZeroOrMoreTQLayer(_zomifier, self.rdf) results = GraphObjectQuerier(v, g, parallel=False, hop_scorer=goq_hop_scorer)() self._remove_value(v) return results
def load(graph, start=None, target_type=None, context=None, idents=None): L.debug("load: graph %s start %s target_type %s context %s", graph, start, target_type, context) if idents is None: g = ZeroOrMoreTQLayer(zomifier(target_type), graph) idents = GraphObjectQuerier(start, g, parallel=False, hop_scorer=goq_hop_scorer)() if idents: choices = graph.triples_choices( (list(idents), rdflib.RDF['type'], None)) choices = list(choices) grouped_type_triples = groupby(choices, lambda x: x[0]) hit = False for ident, type_triples in grouped_type_triples: hit = True types = set() for __, __, rdf_type in type_triples: types.add(rdf_type) tt = () if target_type is None else (target_type, ) the_type = get_most_specific_rdf_type(types, context, bases=tt) yield oid(ident, the_type, context) if not hit: for ident in idents: tt = () if target_type is None else (target_type, ) the_type = get_most_specific_rdf_type((), context, bases=tt) yield oid(ident, the_type, context) else: return
def load(self): idents = GraphObjectQuerier(self, self.rdf, parallel=False)() if idents: choices = self.rdf.triples_choices( (list(idents), R.RDF['type'], None)) grouped_type_triples = groupby(choices, lambda x: x[0]) for ident, type_triples in grouped_type_triples: types = set() for __, __, rdf_type in type_triples: types.add(rdf_type) the_type = get_most_specific_rdf_type(types) yield oid(ident, the_type) else: return
def get(self): results = None owner = self.owner if owner.defined: self._ensure_fresh_po_cache() results = set() for pred, obj in owner.po_cache.cache: if pred == self.link: results.add(obj) else: v = Variable("var" + str(id(self))) self._insert_value(v) results = GraphObjectQuerier(v, self.rdf, parallel=False)() self._remove_value(v) return results
def count(self): return len(GraphObjectQuerier(self, self.rdf, parallel=False, hop_scorer=goq_hop_scorer)())
def get(self): v = Variable("var" + str(id(self))) self.set(v) results = GraphObjectQuerier(v, self.rdf)() self.unset(v) return results
def count(self): return len(GraphObjectQuerier(self, self.rdf, parallel=False)())