Class TriplePattern

  • All Implemented Interfaces:
    ClauseEntry
    Direct Known Subclasses:
    MutableTriplePattern

    public class TriplePattern
    extends java.lang.Object
    implements ClauseEntry
    Datastructure which defines a triple pattern as used in simple rules and in find interfaces.

    Wildcards are recorded by using Node_RuleVariable entries rather than nulls because they can be named. If a null is specified that is converted to a variable of name "". Note that whilst some engines might simply require Node_Variables the forward engine requires variables represented using the more specialized subclass - Node_RuleVariable.

    It would make more sense to have TriplePattern subclass Triple but that is final for some strange reason.

    • Constructor Summary

      Constructors 
      Constructor Description
      TriplePattern​(Node subject, Node predicate, Node object)
      Constructor - builds a pattern from three nodes, use Node_RuleVariables as variables, use a variable with an empty name as a wildcard, can also use null as a wildcard.
      TriplePattern​(Triple match)
      Constructor - builds a degenerate pattern from a simple triple.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Triple asTriple()
      Return the triple pattern as a triple
      Triple asTripleMatch()
      Return the triple pattern as a triple match (concrete terms + Node.ANY)
      boolean compatibleWith​(TriplePattern pattern)
      Compare two patterns for compatibility - i.e.
      boolean equals​(java.lang.Object o)
      Equality override - used so that TriplePattern variants (same to within variable renaming) test as equals
      Node getObject()
      Returns the object.
      Node getPredicate()
      Returns the predicate.
      Node getSubject()
      Returns the subject.
      int hashCode()
      hash function override
      boolean isGround()
      Test if the pattern is ground, contains no variables.
      boolean isLegal()
      Check a pattern to see if it is legal, used to exclude backchaining goals that could never be satisfied.
      boolean sameAs​(java.lang.Object o)
      Compare triple patterns, taking into account variable indices.
      static java.lang.String simplePrintString​(Node n)
      Simplified printable name for a node
      static java.lang.String simplePrintString​(Triple t)
      Simplified printable name for a triple
      boolean subsumes​(TriplePattern arg)
      Compare two patterns and return true if arg is a more specific (more grounded) version of this one.
      java.lang.String toString()
      Printable string
      boolean variantOf​(TriplePattern pattern)
      Test if a pattern is just a variant of this pattern.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TriplePattern

        public TriplePattern​(Node subject,
                             Node predicate,
                             Node object)
        Constructor - builds a pattern from three nodes, use Node_RuleVariables as variables, use a variable with an empty name as a wildcard, can also use null as a wildcard.
      • TriplePattern

        public TriplePattern​(Triple match)
        Constructor - builds a degenerate pattern from a simple triple. This would be much easier if we merged Triples and TriplePatterns!
    • Method Detail

      • getObject

        public Node getObject()
        Returns the object.
        Returns:
        Node
      • getPredicate

        public Node getPredicate()
        Returns the predicate.
        Returns:
        Node
      • getSubject

        public Node getSubject()
        Returns the subject.
        Returns:
        Node
      • asTripleMatch

        public Triple asTripleMatch()
        Return the triple pattern as a triple match (concrete terms + Node.ANY)
      • asTriple

        public Triple asTriple()
        Return the triple pattern as a triple
      • compatibleWith

        public boolean compatibleWith​(TriplePattern pattern)
        Compare two patterns for compatibility - i.e. potentially unifiable. Two patterns are "compatible" in the sense we mean here if all their ground terms match. A variable in either pattern can match a ground term or a variable in the other. We are not, currently, checking for multiple occurances of the same variable. Functor-valued object literals are treated as a special case which are only checked for name/arity matching.
      • variantOf

        public boolean variantOf​(TriplePattern pattern)
        Test if a pattern is just a variant of this pattern. I.e. it is the same up to variable renaming. This takes into account multiple occurances of the same variable.
      • isLegal

        public boolean isLegal()
        Check a pattern to see if it is legal, used to exclude backchaining goals that could never be satisfied. A legal pattern cannot have literals in the subject or predicate positions and is not allowed nested functors in the object.
      • subsumes

        public boolean subsumes​(TriplePattern arg)
        Compare two patterns and return true if arg is a more specific (more grounded) version of this one. Does not handle functors.
      • isGround

        public boolean isGround()
        Test if the pattern is ground, contains no variables.
      • toString

        public java.lang.String toString()
        Printable string
        Overrides:
        toString in class java.lang.Object
      • simplePrintString

        public static java.lang.String simplePrintString​(Triple t)
        Simplified printable name for a triple
      • simplePrintString

        public static java.lang.String simplePrintString​(Node n)
        Simplified printable name for a node
      • equals

        public boolean equals​(java.lang.Object o)
        Equality override - used so that TriplePattern variants (same to within variable renaming) test as equals
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        hash function override
        Overrides:
        hashCode in class java.lang.Object
      • sameAs

        public boolean sameAs​(java.lang.Object o)
        Compare triple patterns, taking into account variable indices. The equality function ignores differences between variables.
        Specified by:
        sameAs in interface ClauseEntry