1. okfn
  2. ordf

Commits

William Waites  committed 6b37931

add 'one' and 'exists' methods on graphs

  • Participants
  • Parent commits c5bdb77
  • Branches default

Comments (0)

Files changed (1)

File ordf/graph.py

View file
     def bnc(self, triple, *av, **kw):
         """
         Return the BNode closure(s) for triples that are matched
-        by the given triple. Any additional positional or keyword
+        by the given "triple". Any additional positional or keyword
         arguments are passed to the constructor for the new graph.
         """
         result = Graph(*av, **kw)
 
     def replace(self, old, new, *av, **kw):
         """
-        Return a graph where triple *old* is replaced with triple
-        *new*. Any additional positional or keyword arguments are
+        Return a graph where triple "old" is replaced with triple
+        "new". Any additional positional or keyword arguments are
         passed to the constructor for the new graph.
         """
         result = Graph(*av, **kw)
             result.add((s,p,o))
         return result
 
+    def one(self, triple):
+        """
+        Return one matching "triple" or "None"
+        """
+        for statement in self.triples(triple):
+            return statement
+
+    def exists(self, triple):
+        """
+        Return "True" if "triple" exists, "False" otherwise
+        """
+        statement = self.one(triple)
+        if statement is not None:
+            return True
+        return False
+
 class Graph(_Graph, _Common):
     def __init__(self, store="IOMemory", identifier=None, **kw):
         if __rdflib_version__ == 2: