def __getitem__(self, key): """Fetch predicates off this subject by key dictionary-style. This is the primary mechanism for predicate access. You can either provide a predicate name, as a complete URL or CURIE: resource['rdfs:label'] resource['http://www.w3.org/2000/01/rdf-schema#label'] Or a predicate name and a datatype or language: resource['rdfs:label', 'en'] Passing in a value of None will result in all values for the predicate in question being returned.""" predicate, objects = self._objects_for_key(key) if predicate not in self.scalars or (isinstance(key, tuple) and key[1] is None): def getitem_iter_results(): for obj in objects: yield self.classify(self.graph, obj) return getitem_iter_results() else: return self.classify(self.graph, util.one_or_none(objects))
def get_scalar(self, key): """As __getitem__ access, but pretend the key is a scalar even if it isn't. Expect random exceptions if using this carelessly.""" predicate, objects = self._objects_for_key(key) return self.classify(self.graph, util.one_or_none(objects))