org.coode.owlapi.rdfxml.parser
Class OWLRDFConsumer

java.lang.Object
  extended by org.coode.owlapi.rdfxml.parser.OWLRDFConsumer
All Implemented Interfaces:
RDFConsumer
Direct Known Subclasses:
OWLRDFConsumerAdapter

public class OWLRDFConsumer
extends java.lang.Object
implements RDFConsumer

Author: Matthew Horridge
The University Of Manchester
Bio-Health Informatics Group
Date: 07-Dec-2006

A parser/interpreter for an RDF graph which represents an OWL ontology. The consumer interprets triple patterns in the graph to produce the appropriate OWLAPI entities, class expressions and axioms. The parser is based on triple handlers. A given triple handler handles a specific type of triple. Generally speaking this is based on the predicate of a triple, for example, A rdfs:subClassOf B is handled by a subClassOf handler. A handler determines if it can handle a triple in a streaming mode (i.e. while parsing is taking place) or if it can handle a triple after parsing has taken place and the complete graph is in memory. Once a handler handles a triple, that triple is deemed to have been consumed an is discarded. The parser attempts to consume as many triples as possible while streaming parsing is taking place. Whether or not a triple can be consumed dIRIng parsing is determined by installed triple handlers.


Field Summary
static java.util.logging.Logger logger
           
 
Constructor Summary
OWLRDFConsumer(OWLOntologyManager owlOntologyManager, OWLOntology ontology, AnonymousNodeChecker checker)
           
 
Method Summary
 void addAnnotatedSource(IRI annotatedAnonSource, IRI annotationMainNode)
          Records an annotation of an anonymous node (either an annotation of an annotation, or an annotation of an axiom for example)
protected  void addAnnotationIRI(IRI iri)
           
protected  void addAnnotationProperty(IRI iri)
           
 void addAxiom(IRI axiomIRI)
           
protected  void addAxiom(OWLAxiom axiom)
           
 void addFirst(IRI subject, IRI object)
           
 void addFirst(IRI subject, OWLLiteral object)
           
protected  void addImport(OWLImportsDeclaration declaration)
           
protected  void addIndividual(IRI iri)
           
 void addList(IRI iri)
           
 void addModelAttribte(java.lang.String string, java.lang.String string1)
          Receives the notification that the attribute and its value has been parsed.
 void addOntology(IRI iri)
           
protected  void addOntologyAnnotation(OWLAnnotation annotation)
           
protected  void addOWLClass(IRI iri)
           
protected  void addOWLDataProperty(IRI iri)
           
 void addOWLDataRange(IRI iri)
           
protected  void addOWLDatatype(IRI iri)
           
protected  void addOWLObjectProperty(IRI iri)
           
protected  void addRDFProperty(IRI iri)
           
 void addRest(IRI subject, IRI object)
           
protected  void addRestriction(IRI iri)
           
protected  void addSharedAnonymousNode(IRI iri, java.lang.Object translation)
           
protected  void addSWRLBuiltInAtom(IRI iri)
           
protected  void addSWRLClassAtom(IRI iri)
           
protected  void addSWRLDataPropertyAtom(IRI iri)
           
protected  void addSWRLDataRangeAtom(IRI iri)
           
protected  void addSWRLDifferentFromAtom(IRI iri)
           
protected  void addSWRLIndividualPropertyAtom(IRI iri)
           
protected  void addSWRLRule(IRI iri)
           
protected  void addSWRLSameAsAtom(IRI iri)
           
protected  void addSWRLVariable(IRI iri)
           
 void addTriple(IRI subject, IRI predicate, IRI object)
           
 void addTriple(IRI subject, IRI predicate, OWLLiteral con)
           
protected  void applyChange(OWLOntologyChange change)
           
 IRI checkForSynonym(IRI original)
           
protected  void consumeTriple(IRI subject, IRI predicate, IRI object)
           
protected  void consumeTriple(IRI subject, IRI predicate, OWLLiteral con)
           
 void endModel()
          This is where we do all remaining parsing
 java.util.Set<IRI> getAnnotatedSourceAnnotationMainNodes(IRI source)
          Gets the main nodes of annotations that annotated the specified source
 OWLClassExpression getClassExpressionIfTranslated(IRI mainNode)
           
 OWLDataFactory getDataFactory()
           
 OWLLiteral getFirstLiteral(IRI subject)
           
 IRI getFirstResource(IRI subject, boolean consume)
           
 OWLAxiom getLastAddedAxiom()
           
 OWLLiteral getLiteralObject(IRI subject, IRI predicate, boolean consume)
           
 java.util.Set<IRI> getOntologies()
           
 OWLOntology getOntology()
           
 RDFXMLOntologyFormat getOntologyFormat()
           
protected  OWLClass getOWLClass(IRI iri)
           
protected  OWLDataProperty getOWLDataProperty(IRI iri)
           
protected  OWLIndividual getOWLIndividual(IRI iri)
           
protected  OWLObjectProperty getOWLObjectProperty(IRI iri)
           
 OWLOntologyManager getOWLOntologyManager()
           
 java.util.Set<OWLAnnotation> getPendingAnnotations()
          Gets any annotations that were translated since the last call of this method (calling this method clears the current pending annotations)
 java.util.Set<IRI> getPredicatesBySubject(IRI subject)
           
 IRI getResourceObject(IRI subject, IRI predicate, boolean consume)
           
 IRI getRest(IRI subject, boolean consume)
           
protected  java.lang.Object getSharedAnonymousNode(IRI iri)
           
 void handle(IRI subject, IRI predicate, IRI object)
          Handles triples in a non-streaming mode.
 void handle(IRI subject, IRI predicate, OWLLiteral object)
           
 boolean hasPredicate(IRI subject, IRI predicate)
           
 boolean hasPredicateObject(IRI subject, IRI predicate, IRI object)
           
 void importsClosureChanged()
           
 void includeModel(java.lang.String string, java.lang.String string1)
          Receives the notification that the model being parsed includes another model with supplied URIs.
protected  boolean isAnnotation(IRI iri)
           
protected  boolean isAnnotationProperty(IRI iri)
           
protected  boolean isAnonymousNode(IRI iri)
          Checks whether a node is anonymous.
 boolean isAxiom(IRI iri)
           
protected  boolean isClass(IRI iri)
           
protected  boolean isDataPropertyOnly(IRI iri)
           
 boolean isDataRange(IRI iri)
           
protected  boolean isIndividual(IRI iri)
           
 boolean isList(IRI iri, boolean consume)
           
protected  boolean isObjectPropertyOnly(IRI iri)
           
protected  boolean isOntology(IRI iri)
           
protected  boolean isOntologyProperty(IRI iri)
           
protected  boolean isRDFProperty(IRI iri)
           
 boolean isRestriction(IRI iri)
           
protected  boolean isSharedAnonymousNode(IRI iri)
           
 boolean isStrict()
          Determines if strict parsing should be used.
protected  boolean isSWRLBuiltInAtom(IRI iri)
           
protected  boolean isSWRLClassAtom(IRI iri)
           
protected  boolean isSWRLDataRangeAtom(IRI iri)
           
protected  boolean isSWRLDataValuedPropertyAtom(IRI iri)
           
protected  boolean isSWRLDifferentFromAtom(IRI iri)
           
protected  boolean isSWRLIndividualPropertyAtom(IRI iri)
           
protected  boolean isSWRLRule(IRI iri)
           
protected  boolean isSWRLSameAsAtom(IRI iri)
           
protected  boolean isSWRLVariable(IRI iri)
           
 boolean isTriplePresent(IRI subject, IRI predicate, IRI object, boolean consume)
           
 boolean isTriplePresent(IRI subject, IRI predicate, OWLLiteral object, boolean consume)
           
<E extends java.lang.Throwable>
void
iterateLiteralTriples(org.coode.owlapi.rdfxml.parser.OWLRDFConsumer.LiteralTripleIterator<E> iterator)
           
<E extends java.lang.Throwable>
void
iterateResourceTriples(org.coode.owlapi.rdfxml.parser.OWLRDFConsumer.ResourceTripleIterator<E> iterator)
           
 void logicalURI(java.lang.String string)
          Receives the logical URI of the model.
 void setIRIProvider(IRIProvider iriProvider)
           
 void setOntologyFormat(RDFXMLOntologyFormat format)
           
protected  void setOntologyID(OWLOntologyID ontologyID)
           
 void setPendingAnnotations(java.util.Set<OWLAnnotation> annotations)
           
 void setXMLBase(java.lang.String base)
           
 void startModel(java.lang.String string)
          Called when model parsing is started.
 void statementWithLiteralValue(java.lang.String subject, java.lang.String predicate, java.lang.String object, java.lang.String lang, java.lang.String datatype)
          Called when a statement with literal value is added to the model.
 void statementWithResourceValue(java.lang.String subject, java.lang.String predicate, java.lang.String object)
          Called when a statement with resource value is added to the model.
 java.util.Set<OWLAnnotation> translateAnnotations(IRI mainNode)
          Translates the annotation on a main node.
 OWLClassExpression translateClassExpression(IRI mainNode)
           
 OWLDataPropertyExpression translateDataPropertyExpression(IRI iri)
           
 OWLDataRange translateDataRange(IRI iri)
           
 OWLIndividual translateIndividual(IRI node)
           
 OWLObjectPropertyExpression translateObjectPropertyExpression(IRI mainNode)
           
 java.util.Set<OWLClassExpression> translateToClassExpressionSet(IRI mainNode)
           
 java.util.Set<OWLLiteral> translateToConstantSet(IRI mainNode)
           
 java.util.List<OWLDataPropertyExpression> translateToDataPropertyList(IRI mainNode)
           
 java.util.Set<OWLDataRange> translateToDataRangeSet(IRI mainNode)
           
 java.util.Set<OWLFacetRestriction> translateToFacetRestrictionSet(IRI mainNode)
           
 java.util.Set<OWLIndividual> translateToIndividualSet(IRI mainNode)
           
 java.util.List<OWLObjectPropertyExpression> translateToObjectPropertyList(IRI mainNode)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static final java.util.logging.Logger logger
Constructor Detail

OWLRDFConsumer

public OWLRDFConsumer(OWLOntologyManager owlOntologyManager,
                      OWLOntology ontology,
                      AnonymousNodeChecker checker)
Method Detail

isStrict

public boolean isStrict()
Determines if strict parsing should be used. If strict parsing is in opertion then no patching, fixing or type inference should be done.

Returns:
true if strict parsing should be used, otherwise false.

setIRIProvider

public void setIRIProvider(IRIProvider iriProvider)

getOntology

public OWLOntology getOntology()

getOntologyFormat

public RDFXMLOntologyFormat getOntologyFormat()

setOntologyFormat

public void setOntologyFormat(RDFXMLOntologyFormat format)

getDataFactory

public OWLDataFactory getDataFactory()

getPendingAnnotations

public java.util.Set<OWLAnnotation> getPendingAnnotations()
Gets any annotations that were translated since the last call of this method (calling this method clears the current pending annotations)

Returns:
The set (possibly empty) of pending annotations.

setPendingAnnotations

public void setPendingAnnotations(java.util.Set<OWLAnnotation> annotations)

importsClosureChanged

public void importsClosureChanged()

isAnonymousNode

protected boolean isAnonymousNode(IRI iri)
Checks whether a node is anonymous.

Parameters:
iri - The IRI of the node to be checked.
Returns:
true if the node is anonymous, or false if the node is not anonymous.

isSharedAnonymousNode

protected boolean isSharedAnonymousNode(IRI iri)

addSharedAnonymousNode

protected void addSharedAnonymousNode(IRI iri,
                                      java.lang.Object translation)

getSharedAnonymousNode

protected java.lang.Object getSharedAnonymousNode(IRI iri)

addAxiom

protected void addAxiom(OWLAxiom axiom)

applyChange

protected void applyChange(OWLOntologyChange change)

setOntologyID

protected void setOntologyID(OWLOntologyID ontologyID)

addOntologyAnnotation

protected void addOntologyAnnotation(OWLAnnotation annotation)

addImport

protected void addImport(OWLImportsDeclaration declaration)

getLastAddedAxiom

public OWLAxiom getLastAddedAxiom()

addOWLClass

protected void addOWLClass(IRI iri)

addOWLObjectProperty

protected void addOWLObjectProperty(IRI iri)

addIndividual

protected void addIndividual(IRI iri)

isIndividual

protected boolean isIndividual(IRI iri)

addRDFProperty

protected void addRDFProperty(IRI iri)

isRDFProperty

protected boolean isRDFProperty(IRI iri)

addOWLDataProperty

protected void addOWLDataProperty(IRI iri)

addOWLDatatype

protected void addOWLDatatype(IRI iri)

addOWLDataRange

public void addOWLDataRange(IRI iri)

addRestriction

protected void addRestriction(IRI iri)

addAnnotationProperty

protected void addAnnotationProperty(IRI iri)

addAnnotationIRI

protected void addAnnotationIRI(IRI iri)

isAnnotation

protected boolean isAnnotation(IRI iri)

isRestriction

public boolean isRestriction(IRI iri)

isClass

protected boolean isClass(IRI iri)

isObjectPropertyOnly

protected boolean isObjectPropertyOnly(IRI iri)

isDataPropertyOnly

protected boolean isDataPropertyOnly(IRI iri)

isOntologyProperty

protected boolean isOntologyProperty(IRI iri)

isAnnotationProperty

protected boolean isAnnotationProperty(IRI iri)

isOntology

protected boolean isOntology(IRI iri)

getOWLOntologyManager

public OWLOntologyManager getOWLOntologyManager()

addAnnotatedSource

public void addAnnotatedSource(IRI annotatedAnonSource,
                               IRI annotationMainNode)
Records an annotation of an anonymous node (either an annotation of an annotation, or an annotation of an axiom for example)

Parameters:
annotatedAnonSource - The source that the annotation annotates
annotationMainNode - The annotations

getAnnotatedSourceAnnotationMainNodes

public java.util.Set<IRI> getAnnotatedSourceAnnotationMainNodes(IRI source)
Gets the main nodes of annotations that annotated the specified source

Parameters:
source - The source (axiom or annotation main node)
Returns:
The set of main nodes that annotate the specified source

getOWLClass

protected OWLClass getOWLClass(IRI iri)

getOWLObjectProperty

protected OWLObjectProperty getOWLObjectProperty(IRI iri)

getOWLDataProperty

protected OWLDataProperty getOWLDataProperty(IRI iri)

getOWLIndividual

protected OWLIndividual getOWLIndividual(IRI iri)

consumeTriple

protected void consumeTriple(IRI subject,
                             IRI predicate,
                             IRI object)

consumeTriple

protected void consumeTriple(IRI subject,
                             IRI predicate,
                             OWLLiteral con)

addSWRLRule

protected void addSWRLRule(IRI iri)

isSWRLRule

protected boolean isSWRLRule(IRI iri)

addSWRLIndividualPropertyAtom

protected void addSWRLIndividualPropertyAtom(IRI iri)

isSWRLIndividualPropertyAtom

protected boolean isSWRLIndividualPropertyAtom(IRI iri)

addSWRLDataPropertyAtom

protected void addSWRLDataPropertyAtom(IRI iri)

isSWRLDataValuedPropertyAtom

protected boolean isSWRLDataValuedPropertyAtom(IRI iri)

addSWRLClassAtom

protected void addSWRLClassAtom(IRI iri)

isSWRLClassAtom

protected boolean isSWRLClassAtom(IRI iri)

addSWRLSameAsAtom

protected void addSWRLSameAsAtom(IRI iri)

isSWRLSameAsAtom

protected boolean isSWRLSameAsAtom(IRI iri)

addSWRLDifferentFromAtom

protected void addSWRLDifferentFromAtom(IRI iri)

isSWRLDifferentFromAtom

protected boolean isSWRLDifferentFromAtom(IRI iri)

addSWRLDataRangeAtom

protected void addSWRLDataRangeAtom(IRI iri)

isSWRLDataRangeAtom

protected boolean isSWRLDataRangeAtom(IRI iri)

addSWRLBuiltInAtom

protected void addSWRLBuiltInAtom(IRI iri)

isSWRLBuiltInAtom

protected boolean isSWRLBuiltInAtom(IRI iri)

addSWRLVariable

protected void addSWRLVariable(IRI iri)

isSWRLVariable

protected boolean isSWRLVariable(IRI iri)

handle

public void handle(IRI subject,
                   IRI predicate,
                   IRI object)
            throws UnloadableImportException
Handles triples in a non-streaming mode. Type triples whose type is an axiom type, are NOT handled.

Parameters:
subject - The subject of the triple
predicate - The predicate of the triple
object - The object of the triple
Throws:
UnloadableImportException - .

handle

public void handle(IRI subject,
                   IRI predicate,
                   OWLLiteral object)

startModel

public void startModel(java.lang.String string)
                throws org.xml.sax.SAXException
Description copied from interface: RDFConsumer
Called when model parsing is started.

Specified by:
startModel in interface RDFConsumer
Parameters:
string - physical URI of the model
Throws:
org.xml.sax.SAXException

endModel

public void endModel()
              throws org.xml.sax.SAXException
This is where we do all remaining parsing

Specified by:
endModel in interface RDFConsumer
Throws:
org.xml.sax.SAXException

addModelAttribte

public void addModelAttribte(java.lang.String string,
                             java.lang.String string1)
                      throws org.xml.sax.SAXException
Description copied from interface: RDFConsumer
Receives the notification that the attribute and its value has been parsed.

Specified by:
addModelAttribte in interface RDFConsumer
Parameters:
string - the key of the attribute
string1 - the value of the attribute
Throws:
org.xml.sax.SAXException

includeModel

public void includeModel(java.lang.String string,
                         java.lang.String string1)
                  throws org.xml.sax.SAXException
Description copied from interface: RDFConsumer
Receives the notification that the model being parsed includes another model with supplied URIs.

Specified by:
includeModel in interface RDFConsumer
Parameters:
string - logical URI of the model
string1 - physical URI of the model
Throws:
org.xml.sax.SAXException

logicalURI

public void logicalURI(java.lang.String string)
                throws org.xml.sax.SAXException
Description copied from interface: RDFConsumer
Receives the logical URI of the model.

Specified by:
logicalURI in interface RDFConsumer
Parameters:
string - logical URI of the model
Throws:
org.xml.sax.SAXException

checkForSynonym

public IRI checkForSynonym(IRI original)

statementWithLiteralValue

public void statementWithLiteralValue(java.lang.String subject,
                                      java.lang.String predicate,
                                      java.lang.String object,
                                      java.lang.String lang,
                                      java.lang.String datatype)
                               throws org.xml.sax.SAXException
Description copied from interface: RDFConsumer
Called when a statement with literal value is added to the model.

Specified by:
statementWithLiteralValue in interface RDFConsumer
Parameters:
subject - URI of the subject resource
predicate - URI of the predicate resource
object - literal object value
lang - the language
datatype - the URI of the literal's datatype (may be null)
Throws:
org.xml.sax.SAXException

statementWithResourceValue

public void statementWithResourceValue(java.lang.String subject,
                                       java.lang.String predicate,
                                       java.lang.String object)
                                throws org.xml.sax.SAXException
Description copied from interface: RDFConsumer
Called when a statement with resource value is added to the model.

Specified by:
statementWithResourceValue in interface RDFConsumer
Parameters:
subject - URI of the subject resource
predicate - URI of the predicate resource
object - URI of the object resource
Throws:
org.xml.sax.SAXException

translateDataRange

public OWLDataRange translateDataRange(IRI iri)

translateDataPropertyExpression

public OWLDataPropertyExpression translateDataPropertyExpression(IRI iri)

translateObjectPropertyExpression

public OWLObjectPropertyExpression translateObjectPropertyExpression(IRI mainNode)

translateIndividual

public OWLIndividual translateIndividual(IRI node)

translateAnnotations

public java.util.Set<OWLAnnotation> translateAnnotations(IRI mainNode)
Translates the annotation on a main node. Triples whose subject is the specified main node and whose subject is typed an an annotation property (or is a built in annotation property) will be translated to annotation on this main node.

Parameters:
mainNode - The main node
Returns:
The set of annotations on the main node

translateClassExpression

public OWLClassExpression translateClassExpression(IRI mainNode)

getClassExpressionIfTranslated

public OWLClassExpression getClassExpressionIfTranslated(IRI mainNode)

translateToObjectPropertyList

public java.util.List<OWLObjectPropertyExpression> translateToObjectPropertyList(IRI mainNode)

translateToDataPropertyList

public java.util.List<OWLDataPropertyExpression> translateToDataPropertyList(IRI mainNode)

translateToClassExpressionSet

public java.util.Set<OWLClassExpression> translateToClassExpressionSet(IRI mainNode)

translateToConstantSet

public java.util.Set<OWLLiteral> translateToConstantSet(IRI mainNode)

translateToIndividualSet

public java.util.Set<OWLIndividual> translateToIndividualSet(IRI mainNode)

translateToDataRangeSet

public java.util.Set<OWLDataRange> translateToDataRangeSet(IRI mainNode)

translateToFacetRestrictionSet

public java.util.Set<OWLFacetRestriction> translateToFacetRestrictionSet(IRI mainNode)

getPredicatesBySubject

public java.util.Set<IRI> getPredicatesBySubject(IRI subject)

getResourceObject

public IRI getResourceObject(IRI subject,
                             IRI predicate,
                             boolean consume)

getLiteralObject

public OWLLiteral getLiteralObject(IRI subject,
                                   IRI predicate,
                                   boolean consume)

isTriplePresent

public boolean isTriplePresent(IRI subject,
                               IRI predicate,
                               IRI object,
                               boolean consume)

isTriplePresent

public boolean isTriplePresent(IRI subject,
                               IRI predicate,
                               OWLLiteral object,
                               boolean consume)

hasPredicate

public boolean hasPredicate(IRI subject,
                            IRI predicate)

hasPredicateObject

public boolean hasPredicateObject(IRI subject,
                                  IRI predicate,
                                  IRI object)

addList

public void addList(IRI iri)

isList

public boolean isList(IRI iri,
                      boolean consume)

addRest

public void addRest(IRI subject,
                    IRI object)

addFirst

public void addFirst(IRI subject,
                     IRI object)

getFirstResource

public IRI getFirstResource(IRI subject,
                            boolean consume)

getFirstLiteral

public OWLLiteral getFirstLiteral(IRI subject)

getRest

public IRI getRest(IRI subject,
                   boolean consume)

addFirst

public void addFirst(IRI subject,
                     OWLLiteral object)

addOntology

public void addOntology(IRI iri)

getOntologies

public java.util.Set<IRI> getOntologies()

addAxiom

public void addAxiom(IRI axiomIRI)

isAxiom

public boolean isAxiom(IRI iri)

isDataRange

public boolean isDataRange(IRI iri)

iterateResourceTriples

public <E extends java.lang.Throwable> void iterateResourceTriples(org.coode.owlapi.rdfxml.parser.OWLRDFConsumer.ResourceTripleIterator<E> iterator)
                            throws E extends java.lang.Throwable
Throws:
E extends java.lang.Throwable

iterateLiteralTriples

public <E extends java.lang.Throwable> void iterateLiteralTriples(org.coode.owlapi.rdfxml.parser.OWLRDFConsumer.LiteralTripleIterator<E> iterator)
                           throws E extends java.lang.Throwable
Throws:
E extends java.lang.Throwable

addTriple

public void addTriple(IRI subject,
                      IRI predicate,
                      IRI object)

addTriple

public void addTriple(IRI subject,
                      IRI predicate,
                      OWLLiteral con)

setXMLBase

public void setXMLBase(java.lang.String base)