Class OntStatementImpl

java.lang.Object
org.apache.jena.rdf.model.impl.StatementBase
org.apache.jena.rdf.model.impl.StatementImpl
org.apache.jena.ontapi.impl.objects.OntStatementImpl
All Implemented Interfaces:
org.apache.jena.graph.FrontsTriple, OntStatement, org.apache.jena.rdf.model.Statement

public class OntStatementImpl extends org.apache.jena.rdf.model.impl.StatementImpl implements OntStatement
An implementation of Ontology Statement. This is an extended Jena StatementImpl with possibility to add, delete and find annotations in the same form of OntStatement. Annotations can be plain (annotation assertion) or bulk (anonymous resource with rdf:type owl:Axiom or owl:Annotation, for more details see OntAnnotation). The examples of how to write bulk-annotations in RDF-graph see here: 2.2 Translation of Annotations.
See Also:
  • Constructor Details

  • Method Details

    • createOntStatementImpl

      public static OntStatementImpl createOntStatementImpl(org.apache.jena.graph.Triple t, OntGraphModelImpl m)
      Creates an OntStatement impl from the given Triple. The OntStatement has subject, predicate, and object corresponding to those of Triple.
      Parameters:
      t - Triple not null
      m - OntGraphModelImpl model
      Returns:
      OntStatementImpl fresh instance
    • createOntStatementImpl

      public static OntStatementImpl createOntStatementImpl(org.apache.jena.rdf.model.Resource s, org.apache.jena.graph.Node p, org.apache.jena.graph.Node o, OntGraphModelImpl m)
      Creates an OntStatement impl with the given SPO.
      Parameters:
      s - Resource subject
      p - Graph RDF URI Node predicate
      o - Graph RDF Node object
      m - OntGraphModelImpl model
      Returns:
      OntStatementImpl fresh instance
    • createOntStatementImpl

      public static OntStatementImpl createOntStatementImpl(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.graph.Node o, OntGraphModelImpl m)
      Creates an OntStatement-impl with the given SPO.
      Parameters:
      s - Resource subject
      p - Property predicate
      o - Graph RDF Node object
      m - OntGraphModelImpl model
      Returns:
      OntStatementImpl fresh instance
    • createOntStatementImpl

      public static OntStatementImpl createOntStatementImpl(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.RDFNode o, OntGraphModelImpl m)
      Creates an OntStatement impl with the given SPO.
      Parameters:
      s - Resource subject
      p - Property predicate
      o - Model RDF Node object
      m - OntGraphModelImpl model
      Returns:
      OntStatementImpl fresh instance
    • createObject

      public static org.apache.jena.rdf.model.RDFNode createObject(org.apache.jena.graph.Node n, org.apache.jena.enhanced.EnhGraph g)
      Creates an RDF node which might be a literal or resource, in the latter case it is wrapped as OntObjectImpl. The result is used in a statement at object position.
      Parameters:
      n - Node, not null
      g - EnhGraph, not null
      Returns:
      RDFNode
      See Also:
      • StatementImpl.createObject(Node, EnhGraph)
    • createNotAnnotatedOntStatementImpl

      public static OntStatementImpl createNotAnnotatedOntStatementImpl(org.apache.jena.rdf.model.Resource s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.RDFNode o, OntGraphModelImpl m)
      Creates an ont-statement that does not support sub-annotations. The method does not change the model.
      Parameters:
      s - Resource subject
      p - Property predicate
      o - RDFNode object
      m - OntGraphModelImpl model
      Returns:
      OntStatementImpl
    • listAnnotationResources

      public static org.apache.jena.util.iterator.ExtendedIterator<org.apache.jena.rdf.model.Resource> listAnnotationResources(OntGraphModelImpl m, OntStatementImpl s)
      Lists all (bulk) annotation anonymous resources form the specified model and for the given statement (SPO).
      Parameters:
      m - OntGraphModelImpl, not null
      s - OntStatementImpl, not null
      Returns:
      ExtendedIterator of annotation resources
    • getModel

      public OntGraphModelImpl getModel()
      Description copied from interface: OntStatement
      Gets the Ontology RDF Model this Statement was created in.
      Specified by:
      getModel in interface OntStatement
      Specified by:
      getModel in interface org.apache.jena.rdf.model.Statement
      Overrides:
      getModel in class org.apache.jena.rdf.model.impl.StatementBase
      Returns:
      OntModel
    • isRootStatement

      public boolean isRootStatement()
      Answers true iff this statement is a main (i.e. it is a definition of some OntObject). For any other OntStatement (i.e. for those obtained from the model level) the method returns false. A main statement can have annotation assertions attached, while a regular statement is always annotated with bulk annotation objects.
      Returns:
      true if it is a main object statement
      See Also:
    • asRootStatement

      public OntStatement asRootStatement()
    • isLocal

      public boolean isLocal()
      Description copied from interface: OntStatement
      Answers true iff this statement is in the base graph. The method is equivalent to the expression this.getModel().getBaseGraph().contains(this.asTriple()).
      Specified by:
      isLocal in interface OntStatement
      Returns:
      true if it is a local statement
      See Also:
      • OntResource.isLocal()
    • isAnnotationRootStatement

      public boolean isAnnotationRootStatement()
    • getSubject

      public OntObject getSubject()
      Description copied from interface: OntStatement
      An accessor method to return the subject of the statements in form of Ontology Object.
      Specified by:
      getSubject in interface OntStatement
      Specified by:
      getSubject in interface org.apache.jena.rdf.model.Statement
      Overrides:
      getSubject in class org.apache.jena.rdf.model.impl.StatementImpl
      Returns:
      OntObject
      See Also:
      • Statement.getSubject()
    • getSubjectNode

      public org.apache.jena.graph.Node getSubjectNode()
    • getSubject

      public <N extends org.apache.jena.rdf.model.Resource> N getSubject(Class<N> type)
      Description copied from interface: OntStatement
      Answers a typed subject of the statement.
      Specified by:
      getSubject in interface OntStatement
      Type Parameters:
      N - subtype of Resource
      Parameters:
      type - Class type
      Returns:
      Resource instance
      See Also:
    • belongsToAnnotation

      public boolean belongsToAnnotation()
      Answers true iff this statement is a part of Bulk Annotation Ontology Object. This means that it is one of the following:
      
       _:x rdf:type              owl:Annotation .
       _:x p                     v .
       _:x owl:annotatedSource   this .
       _:x owl:annotatedProperty x .
       _:x owl:annotatedTarget   y .
       
      In case of true, this method also caches OntAnnotation in the model.
      Specified by:
      belongsToAnnotation in interface OntStatement
      Returns:
      boolean
      See Also:
    • addAnnotation

      public OntStatement addAnnotation(OntAnnotationProperty property, org.apache.jena.rdf.model.RDFNode value)
      Description copied from interface: OntStatement
      Annotates the statement with the given annotation property and RDF Node value and returns a newly added annotation assertion statement.

      In the special case of a main statement (i.e., if this statement is a result of OntObject.getMainStatement()) the returned OntStatement has the same subject as this statement, and it is called a plain annotation assertion (in this case the method is equivalent to the OntObject.addAnnotation(OntAnnotationProperty, RDFNode) method). Otherwise, the returned statement is a part of a fresh or existing bulk annotation resource and its subject is a blank node.

      Specified by:
      addAnnotation in interface OntStatement
      Parameters:
      property - OntAnnotationProperty named annotation property, not null
      value - RDFNode uri-resource, literal or anonymous individual, not null
      Returns:
      a new Ont-Statement for newly added annotation
      See Also:
    • annotations

      public Stream<OntStatement> annotations()
      Description copied from interface: OntStatement
      Lists all annotations related to this statement. The returned stream consists of annotation assertions listed from the top-level bulk annotations plus plain annotation assertions in the special case of the main statement.
      Specified by:
      annotations in interface OntStatement
      Returns:
      Stream (unordered) of annotation assertion statements with annotation property as predicates, can be empty
      See Also:
    • hasAnnotations

      public boolean hasAnnotations()
      Description copied from interface: OntStatement
      Answers true iff this statement has any annotations attached (either plain or bulk).
      Specified by:
      hasAnnotations in interface OntStatement
      Returns:
      true if it is annotated
    • listAnnotations

      public org.apache.jena.util.iterator.ExtendedIterator<OntStatement> listAnnotations()
      Lists all annotation assertion statements related to this one.
      Returns:
      ExtendedIterator of OntStatements
      See Also:
    • clearAnnotations

      public OntStatementImpl clearAnnotations()
      Description copied from interface: OntStatement
      Removes all sub-annotations including their children.
      Specified by:
      clearAnnotations in interface OntStatement
      Returns:
      this statement to allow cascading calls
      See Also:
    • deleteAnnotation

      public OntStatementImpl deleteAnnotation(OntAnnotationProperty property, org.apache.jena.rdf.model.RDFNode value)
      Description copied from interface: OntStatement
      Deletes the child annotation if present. Does nothing if no assertion found. Throws an exception if specified annotation has it its own annotations. If this statement is not root and the corresponding OntAnnotation resource has no assertions anymore, it deletes the whole OntAnnotation resource also.
      Specified by:
      deleteAnnotation in interface OntStatement
      Parameters:
      property - OntAnnotationProperty named annotation property, not null
      value - RDFNode uri-resource, literal or anonymous individual, not null
      Returns:
      this statement instance to allow cascading calls
      See Also:
    • annotationResources

      public Stream<OntAnnotation> annotationResources()
      Description copied from interface: OntStatement
      Returns the stream of the annotation objects attached to this statement. E.g., for the statement s A t the annotation object looks like
      
       _:b0 a owl:Axiom .
       _:b0 Aj tj .
       _:b0 owl:annotatedSource s .
       _:b0 owl:annotatedProperty A .
       _:b0 owl:annotatedTarget t .
       
      Technically, although it usually does not make sense, it is allowed that a statement may have several such b-nodes.
      Specified by:
      annotationResources in interface OntStatement
      Returns:
      Stream (unordered) of OntAnnotation resources
      See Also:
    • getAnnotationList

      public List<OntAnnotation> getAnnotationList()
      Returns the List of annotations sorted by some internal order.
      Specified by:
      getAnnotationList in interface OntStatement
      Returns:
      List of OntAnnotations
      See Also:
    • listAnnotationResources

      public org.apache.jena.util.iterator.ExtendedIterator<OntAnnotation> listAnnotationResources()
      Returns the iterator of annotation objects attached to this statement.
      Returns:
      ExtendedIterator of OntAnnotations
      See Also:
    • belongsToOWLAnnotation

      public boolean belongsToOWLAnnotation()
    • belongsToOWLAxiom

      public boolean belongsToOWLAxiom()
    • hasAnnotatedProperty

      public boolean hasAnnotatedProperty(org.apache.jena.rdf.model.Property property)
    • hasAnnotatedTarget

      public boolean hasAnnotatedTarget(org.apache.jena.rdf.model.RDFNode object)
    • listSplitStatements

      public org.apache.jena.util.iterator.ExtendedIterator<OntStatement> listSplitStatements()
      Splits the statement into several equivalent ones but with disjoint annotations. Warning: this method stores annotation-resources to memory.
      Returns:
      ExtendedIterator of OntStatements