org.semanticweb.owl.io.owl_rdf
Class OWLConsumer

java.lang.Object
  |
  +--org.semanticweb.owl.io.owl_rdf.OWLConsumer
All Implemented Interfaces:
OWLRDFErrorConstants, edu.unika.aifb.rdf.api.syntax.RDFConsumer

public class OWLConsumer
extends Object
implements edu.unika.aifb.rdf.api.syntax.RDFConsumer, OWLRDFErrorConstants

This is yet another refactoring and reimplementation of the parser. This time, we're collecting all the triples up after parsing and stuffing them into a big data structure. It is likely that this is getting less and less efficient, and at some point we would be better moving to using a parser such as Jena that actually provides some optimised data structures for these kinds of things. However, in the short term it may be fruitful to have multiple implementations of parser.

This parser that doesn't even attempt to do any streaming. Instead it collects the triples as required and then processes them later.

This does introduce memory overhead, but makes the whole process of parsing much easier as we no longer have to make guesses or assumptions about the format of things.

Where it can, the parser will try and fix broken bits of syntax. For example, if we have untyped individuals, these will still be added to the ontology. However, the error handler will be informed of the problem. Thus if the parsing client wishes to strictly enforce, e.g. membership of OWL Lite, it can do so, but if it's happy to have the parser try and fix the problem it can simply ignore (or report) the problem.

In some situations, there are multiple ways in which the triples can be mapped into the data structures. The basic choice boils down to whether assertions about subclasses and equivalences are represented as either axioms or "class definitions". Of course, in terms of formal semantics, there is no difference, but it can be useful to preserve the users intention (see DAML+OIL is Not Enough).

In order to do this, the parser basically tries to identify situations where the triples have been produced via a mapping from the abstract syntax, as described in the OWL Abstract Syntax and Semantics document. As an example, a situation like:

 <class id="a">
   <intersectionOf rdf:parseType="Collection">
     <class id="b"/>
     <class id="c"/>
   </intersectionOf>
 </class>
 
can only arise from a statement of the form:
 Class(a complete intersectionOf(b c))
 
in the abstract syntax. Thus this is dealt with by adding information to the class rather than as an equivalence axiom. Note that this is the only place where intersectionOf can appear in an OWL lite ontology. The only situation where there is ambiguity is in:
 <class id="a">
  <subClassOf>
   <intersectionOf rdf:parseType="Collection">
     <class id="b"/>
     <class id="c"/>
   </intersectionOf>
  </subClassOf>
 </class>
 
In this case, these triples may arise from:
 Class(a partial intersectionOf(b c))
 
or
 SubClass(a intersectionOf(b c))
 
The parser will choose the former wherever it can, on the basis that information relating to the class is then kept in one place.

Limitations and known issues/bugs

Note also that this parser is really targeted at parsing OWL-DL (and Lite) ontologies. If given an OWL-RDF which is actually Full, some of the information in the triples may be ignored or interpreted in a particular way. If this does occur, however, warnings or errors will be communicated to the error handler of the parser.

Since:
05.02.2003

Nested Class Summary
protected  class OWLConsumer.LiteralTriple
           
protected  class OWLConsumer.Triple
           
 
Field Summary
protected  OWLRDFErrorHandler handler
           
protected  Map stringsToURIs
           
protected  int tripleCount
           
protected static int tripleCountChunk
           
 
Fields inherited from interface org.semanticweb.owl.io.owl_rdf.OWLRDFErrorConstants
ANONYMOUS_CLASS_CREATION, CYCLICAL_BNODES, ILLEGAL_SUBPROPERTY, INVALID_URL, INVERSE_FUNCTIONAL_DATA_PROPERTY, IO_ERROR, MALFORMED_ALLDIFFERENT, MALFORMED_DESCRIPTION, MALFORMED_IMPORT, MALFORMED_LIST, MALFORMED_RESTRICTION, MULTIPLE_DEFINITIONS, OTHER, RDF_CLASS, RDF_PROPERTY, STRUCTURE_SHARING, UNSPECIFIED_FUNCTIONAL_PROPERTY, UNTYPED_CLASS, UNTYPED_DATATYPE, UNTYPED_INDIVIDUAL, UNTYPED_ONTOLOGY, UNTYPED_PROPERTY, UNTYPED_PROPERTY_DATA, UNTYPED_PROPERTY_OBJECT, UNTYPED_URI, UNUSED_TRIPLES, URL_IO_ERROR, XML_PROBLEM
 
Constructor Summary
OWLConsumer(OWLOntology onto)
          Create a new consumer that will parse into the given ontology
 
Method Summary
protected  void additionalParsingHook()
          This function provides a hook for parser extensions.
protected  void addLiteralTriple(URI s, URI p, String o, String l, String dt)
           
 void addModelAttribte(String arg0, String arg1)
           
protected  void addToMap(Map map, Object key, Object value)
           
protected  void addTriple(URI s, URI p, URI o)
           
protected  void applyChange(OntologyChange oc)
           
protected  void checkAndConsumeBNode(URI bnode)
          Check to see if the given node is a bnode, and if so, whether it's been used before.
protected  void checkBooleans()
          Check that any booleans are declared properly.
protected  void checkForMalformedLists()
           
protected  void checkForOneOfs()
          Check that any oneOfs are declared properly.
protected  void checkForRDFProperties()
          Check that any properties declared using rdf:Property have also been dealt with properly.
protected  void checkForRDFSClasses()
          Check that anything declared as an rdfs:Class has been dealt with properly.
protected  void checkForUndefinedClasses()
           
protected  void checkForUndefinedDataProperties()
           
protected  void checkForUndefinedObjectProperties()
           
protected  void checkForUndefinedOntologies()
           
protected  void checkForUntypedIndividuals()
           
protected  void createAnnotationInstance(OWLOntology onto, URI subject, URI predicate, Object object)
           
protected  OWLAnnotationProperty createAnnotationProperty(OWLOntology onto, URI uri)
           
protected  OWLClass createClass(OWLOntology onto, URI uri)
          Method createClass.
protected  OWLDataProperty createDataProperty(OWLOntology onto, URI uri)
           
protected  void createDataPropertyInstance(OWLOntology onto, URI subject, URI predicate, String datatype, String language, String object)
           
protected  OWLDataType createDatatype(OWLOntology onto, URI uri)
          Method createDatatype.
protected  void createDifferentFrom(OWLOntology onto, URI subj, URI obj)
           
protected  void createDomain(OWLOntology onto, URI property, URI domain)
           
protected  void createEquivalentProperty(OWLOntology onto, URI subj, URI obj)
           
protected  void createInverseOf(OWLOntology onto, URI subj, URI obj)
          We assume that inverse of must apply to object properties.
protected  OWLObjectProperty createObjectProperty(OWLOntology onto, URI uri)
           
protected  void createOntology(OWLOntology onto, String subj)
          Method createOntology.
protected  void createPropertyInstance(OWLOntology onto, URI subj, URI pred, URI obj)
           
protected  void createRange(OWLOntology onto, URI property, URI range)
          Method createRange.
protected  void createSameIndividualAs(OWLOntology onto, URI subj, URI obj)
          Method createSameIndividualAs.
protected  void createSubProperty(OWLOntology onto, URI subj, URI obj)
           
protected  String dumpTriples()
           
 void endModel()
           
protected  void error(String message)
           
protected  OWLClass getAndAssumeOWLClass(URI uri)
           
protected  Set getByPredicate(String predicate)
           
protected  Set getByPredicate(URI predicate)
           
protected  Set getLiterals(String subject, String predicate)
           
protected  Set getLiterals(URI subject, URI predicate)
           
protected  Set getObjects(String subject, String predicate)
           
protected  Set getObjects(URI subject, URI predicate)
           
protected  OWLAnnotationProperty getOrCreateAnnotationProperty(URI uri)
           
protected  OWLDataProperty getOrCreateDataProperty(URI uri)
           
protected  OWLObjectProperty getOrCreateObjectProperty(URI uri)
           
protected  OWLProperty getProperty(URI uri)
          Returns a property with the given uri if it is created in the ontology null otherwise
protected  Object getSingletonObject(Set s)
           
protected  Set getSubjects(String predicate, String object)
           
protected  Set getSubjects(URI predicate, URI object)
           
protected  OWLConsumer.Triple getTriple(String subject, String predicate, String object)
           
protected  OWLConsumer.Triple getTriple(URI subject, URI predicate, URI object)
           
protected  void importOntology(OWLOntology onto, URI subj, URI obj)
          Method importOntology.
 void includeModel(String arg0, String arg1)
           
protected  boolean isAnonymousNode(String str)
           
protected  boolean isObject(URI object)
           
protected  boolean languageMachineryType(URI uri)
          Returns true if it's the uri of one of a number of language things
 void logicalURI(String arg0)
           
protected  URI newURI(String u)
           
protected  void owlFullConstruct(int code, String message)
           
protected  void owlFullConstruct(int code, String message, Object obj)
           
protected  int parseInt(String str, String type)
           
protected  void rdfListToSet(URI start, Set mySet)
          Takes a URI that should be the URI of an RDF listm and returns a collection of those things that form the elements of the list.
protected  void releaseTripleModel()
           
protected  void setAssumptions(HashSet[] assumptions)
          Set the assumptions that this consumer should be making about the objects that its parsing.
protected  void setCheckDefinitions(boolean b)
           
 void setIncludeAnnotationContent(boolean b)
          Control whether the consumer should include data annotatations.
 void setOWLRDFErrorHandler(OWLRDFErrorHandler h)
           
 void setOWLRDFParser(OWLRDFParser p)
           
 void startModel(String arg0)
           
 void statementWithLiteralValue(String subject, String predicate, String object, String language, String datatype)
          Called when a statement with literal value is added to the model.
 void statementWithResourceValue(String subj, String pred, String obj)
           
protected  OWLDescription translateCardinalityRestriction(URI uri, URI propURI, int type, boolean obj)
           
protected  OWLDataRange translateDataRange(URI range)
           
protected  OWLDescription translateDescription(URI uri)
          Returns an OWLDescription that corresponds to the given URI.
protected  OWLIndividual translateIndividual(URI uri)
           
protected  OWLDescription translateRestriction(URI uri, URI propURI, int type, boolean obj)
          Returns a translation of the given URI
protected  boolean tripleExists(String subject, String predicate)
           
protected  boolean tripleExists(String subject, String predicate, String object)
           
protected  boolean tripleExists(URI subject, URI predicate)
           
protected  boolean tripleExists(URI subject, URI predicate, URI object)
           
protected  Set uriToClassSet(Set uriSet)
          Takes a URI representing a list of descriptions and returns a collection of descriptions obtained by translating those descriptions.
 Set uriToIndividualSet(Set uriSet)
           
protected  void warning(String message)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tripleCount

protected int tripleCount

tripleCountChunk

protected static int tripleCountChunk

stringsToURIs

protected Map stringsToURIs

handler

protected OWLRDFErrorHandler handler
Constructor Detail

OWLConsumer

public OWLConsumer(OWLOntology onto)
            throws OWLException
Create a new consumer that will parse into the given ontology

Method Detail

setOWLRDFParser

public void setOWLRDFParser(OWLRDFParser p)

setIncludeAnnotationContent

public void setIncludeAnnotationContent(boolean b)
Control whether the consumer should include data annotatations. If set to false, data annotations are not added to the model. This can dramatically improve the performance of, for example, validation, as it means that large data sttuctures are not being built. The validator doesn't need to know anything about the annotation content to do its work, as long as it is able to work out whether things are being used as annotation proeprties or not.


owlFullConstruct

protected void owlFullConstruct(int code,
                                String message)
                         throws SAXException
SAXException

owlFullConstruct

protected void owlFullConstruct(int code,
                                String message,
                                Object obj)
                         throws SAXException
SAXException

error

protected void error(String message)
              throws SAXException
SAXException

warning

protected void warning(String message)
                throws SAXException
SAXException

setOWLRDFErrorHandler

public void setOWLRDFErrorHandler(OWLRDFErrorHandler h)

rdfListToSet

protected void rdfListToSet(URI start,
                            Set mySet)
                     throws SAXException
Takes a URI that should be the URI of an RDF listm and returns a collection of those things that form the elements of the list. These will either be URIs or pairs of Strings in the case of literal values.

SAXException

uriToClassSet

protected Set uriToClassSet(Set uriSet)
                     throws SAXException
Takes a URI representing a list of descriptions and returns a collection of descriptions obtained by translating those descriptions.

SAXException

uriToIndividualSet

public Set uriToIndividualSet(Set uriSet)
                       throws SAXException
SAXException

setAssumptions

protected void setAssumptions(HashSet[] assumptions)
Set the assumptions that this consumer should be making about the objects that its parsing. This allows us to deal with things spread across a number of ontologies.


setCheckDefinitions

protected void setCheckDefinitions(boolean b)

startModel

public void startModel(String arg0)
                throws SAXException
Specified by:
startModel in interface edu.unika.aifb.rdf.api.syntax.RDFConsumer
SAXException
See Also:
RDFConsumer.startModel(String)

getProperty

protected OWLProperty getProperty(URI uri)
                           throws OWLException
Returns a property with the given uri if it is created in the ontology null otherwise

OWLException

endModel

public void endModel()
              throws SAXException
Specified by:
endModel in interface edu.unika.aifb.rdf.api.syntax.RDFConsumer
SAXException
See Also:
RDFConsumer.endModel()

translateDescription

protected OWLDescription translateDescription(URI uri)
                                       throws SAXException
Returns an OWLDescription that corresponds to the given URI.

SAXException

translateRestriction

protected OWLDescription translateRestriction(URI uri,
                                              URI propURI,
                                              int type,
                                              boolean obj)
                                       throws SAXException
Returns a translation of the given URI

SAXException

translateCardinalityRestriction

protected OWLDescription translateCardinalityRestriction(URI uri,
                                                         URI propURI,
                                                         int type,
                                                         boolean obj)
                                                  throws SAXException
SAXException

translateIndividual

protected OWLIndividual translateIndividual(URI uri)
                                     throws SAXException
SAXException

translateDataRange

protected OWLDataRange translateDataRange(URI range)
                                   throws OWLException,
                                          SAXException
OWLException
SAXException

statementWithResourceValue

public void statementWithResourceValue(String subj,
                                       String pred,
                                       String obj)
                                throws SAXException
Specified by:
statementWithResourceValue in interface edu.unika.aifb.rdf.api.syntax.RDFConsumer
SAXException
See Also:
RDFConsumer.statementWithResourceValue(String, String, String)

statementWithLiteralValue

public void statementWithLiteralValue(String subject,
                                      String predicate,
                                      String object,
                                      String language,
                                      String datatype)
                               throws SAXException
Called when a statement with literal value is added to the model.

Specified by:
statementWithLiteralValue in interface edu.unika.aifb.rdf.api.syntax.RDFConsumer
Parameters:
subject - URI of the subject resource
predicate - URI of the predicate resource
object - literal object value
language - the language
SAXException

createPropertyInstance

protected void createPropertyInstance(OWLOntology onto,
                                      URI subj,
                                      URI pred,
                                      URI obj)
                               throws SAXException
SAXException

createSameIndividualAs

protected void createSameIndividualAs(OWLOntology onto,
                                      URI subj,
                                      URI obj)
                               throws SAXException
Method createSameIndividualAs.

Parameters:
onto -
subj -
obj -
SAXException

createInverseOf

protected void createInverseOf(OWLOntology onto,
                               URI subj,
                               URI obj)
                        throws SAXException
We assume that inverse of must apply to object properties.

SAXException

createDifferentFrom

protected void createDifferentFrom(OWLOntology onto,
                                   URI subj,
                                   URI obj)
                            throws SAXException
SAXException

createEquivalentProperty

protected void createEquivalentProperty(OWLOntology onto,
                                        URI subj,
                                        URI obj)
                                 throws SAXException
SAXException

createSubProperty

protected void createSubProperty(OWLOntology onto,
                                 URI subj,
                                 URI obj)
                          throws SAXException
SAXException

createRange

protected void createRange(OWLOntology onto,
                           URI property,
                           URI range)
                    throws SAXException
Method createRange.

Parameters:
onto -
SAXException

createDomain

protected void createDomain(OWLOntology onto,
                            URI property,
                            URI domain)
                     throws SAXException
SAXException

importOntology

protected void importOntology(OWLOntology onto,
                              URI subj,
                              URI obj)
                       throws SAXException
Method importOntology.

Parameters:
onto -
subj -
obj -
SAXException

createObjectProperty

protected OWLObjectProperty createObjectProperty(OWLOntology onto,
                                                 URI uri)

createAnnotationProperty

protected OWLAnnotationProperty createAnnotationProperty(OWLOntology onto,
                                                         URI uri)

createDataProperty

protected OWLDataProperty createDataProperty(OWLOntology onto,
                                             URI uri)
                                      throws SAXException
SAXException

getOrCreateObjectProperty

protected OWLObjectProperty getOrCreateObjectProperty(URI uri)
                                               throws SAXException
SAXException

getOrCreateAnnotationProperty

protected OWLAnnotationProperty getOrCreateAnnotationProperty(URI uri)
                                                       throws SAXException
SAXException

getOrCreateDataProperty

protected OWLDataProperty getOrCreateDataProperty(URI uri)
                                           throws SAXException
SAXException

createOntology

protected void createOntology(OWLOntology onto,
                              String subj)
                       throws SAXException
Method createOntology.

Parameters:
onto -
subj -
SAXException

createClass

protected OWLClass createClass(OWLOntology onto,
                               URI uri)
                        throws SAXException
Method createClass. This should only be called when you're damn sure that the class really is a class.

Parameters:
onto -
SAXException

createDatatype

protected OWLDataType createDatatype(OWLOntology onto,
                                     URI uri)
                              throws SAXException
Method createDatatype.

Parameters:
onto -
SAXException

createDataPropertyInstance

protected void createDataPropertyInstance(OWLOntology onto,
                                          URI subject,
                                          URI predicate,
                                          String datatype,
                                          String language,
                                          String object)
                                   throws SAXException
SAXException

createAnnotationInstance

protected void createAnnotationInstance(OWLOntology onto,
                                        URI subject,
                                        URI predicate,
                                        Object object)
                                 throws SAXException
SAXException

logicalURI

public void logicalURI(String arg0)
                throws SAXException
Specified by:
logicalURI in interface edu.unika.aifb.rdf.api.syntax.RDFConsumer
SAXException
See Also:
RDFConsumer.logicalURI(String)

includeModel

public void includeModel(String arg0,
                         String arg1)
                  throws SAXException
Specified by:
includeModel in interface edu.unika.aifb.rdf.api.syntax.RDFConsumer
SAXException
See Also:
RDFConsumer.includeModel(String, String)

addModelAttribte

public void addModelAttribte(String arg0,
                             String arg1)
                      throws SAXException
Specified by:
addModelAttribte in interface edu.unika.aifb.rdf.api.syntax.RDFConsumer
SAXException
See Also:
RDFConsumer.addModelAttribte(String, String)

applyChange

protected void applyChange(OntologyChange oc)
                    throws OWLException
OWLException

getAndAssumeOWLClass

protected OWLClass getAndAssumeOWLClass(URI uri)
                                 throws SAXException
SAXException

isAnonymousNode

protected boolean isAnonymousNode(String str)

addToMap

protected void addToMap(Map map,
                        Object key,
                        Object value)

getSingletonObject

protected Object getSingletonObject(Set s)

checkForUntypedIndividuals

protected void checkForUntypedIndividuals()
                                   throws SAXException
SAXException

checkForUndefinedOntologies

protected void checkForUndefinedOntologies()
                                    throws SAXException
SAXException

checkForUndefinedClasses

protected void checkForUndefinedClasses()
                                 throws SAXException
SAXException

checkForUndefinedObjectProperties

protected void checkForUndefinedObjectProperties()
                                          throws SAXException
SAXException

checkForUndefinedDataProperties

protected void checkForUndefinedDataProperties()
                                        throws SAXException
SAXException

checkForRDFProperties

protected void checkForRDFProperties()
                              throws SAXException
Check that any properties declared using rdf:Property have also been dealt with properly.

SAXException

checkForRDFSClasses

protected void checkForRDFSClasses()
                            throws SAXException
Check that anything declared as an rdfs:Class has been dealt with properly.

SAXException

checkForOneOfs

protected void checkForOneOfs()
                       throws SAXException
Check that any oneOfs are declared properly.

SAXException

checkBooleans

protected void checkBooleans()
                      throws SAXException
Check that any booleans are declared properly.

SAXException

checkForMalformedLists

protected void checkForMalformedLists()
                               throws SAXException
SAXException

releaseTripleModel

protected void releaseTripleModel()

addTriple

protected void addTriple(URI s,
                         URI p,
                         URI o)
                  throws SAXException
SAXException

addLiteralTriple

protected void addLiteralTriple(URI s,
                                URI p,
                                String o,
                                String l,
                                String dt)

getSubjects

protected Set getSubjects(String predicate,
                          String object)
                   throws SAXException
SAXException

getSubjects

protected Set getSubjects(URI predicate,
                          URI object)

getObjects

protected Set getObjects(String subject,
                         String predicate)
                  throws SAXException
SAXException

getObjects

protected Set getObjects(URI subject,
                         URI predicate)

getLiterals

protected Set getLiterals(String subject,
                          String predicate)
                   throws SAXException
SAXException

getLiterals

protected Set getLiterals(URI subject,
                          URI predicate)

getByPredicate

protected Set getByPredicate(URI predicate)

getByPredicate

protected Set getByPredicate(String predicate)
                      throws SAXException
SAXException

isObject

protected boolean isObject(URI object)
                    throws SAXException
SAXException

tripleExists

protected boolean tripleExists(String subject,
                               String predicate)
                        throws SAXException
SAXException

tripleExists

protected boolean tripleExists(URI subject,
                               URI predicate)
                        throws SAXException
SAXException

tripleExists

protected boolean tripleExists(URI subject,
                               URI predicate,
                               URI object)
                        throws SAXException
SAXException

tripleExists

protected boolean tripleExists(String subject,
                               String predicate,
                               String object)
                        throws SAXException
SAXException

getTriple

protected OWLConsumer.Triple getTriple(URI subject,
                                       URI predicate,
                                       URI object)
                                throws SAXException
SAXException

getTriple

protected OWLConsumer.Triple getTriple(String subject,
                                       String predicate,
                                       String object)
                                throws SAXException
SAXException

dumpTriples

protected String dumpTriples()

languageMachineryType

protected boolean languageMachineryType(URI uri)
Returns true if it's the uri of one of a number of language things


parseInt

protected int parseInt(String str,
                       String type)
                throws SAXException
SAXException

checkAndConsumeBNode

protected void checkAndConsumeBNode(URI bnode)
                             throws SAXException
Check to see if the given node is a bnode, and if so, whether it's been used before. If so, we're in Full. If not, mark as used and carry on.

SAXException

newURI

protected URI newURI(String u)
              throws URISyntaxException
URISyntaxException

additionalParsingHook

protected void additionalParsingHook()
                              throws SAXException
This function provides a hook for parser extensions. It gets called after the ontology has been parsed, but before the "extra" stuff that hasn't been used is handled. This will allow us to extend the RDF parser and deal with extensions to OWL, such as rules.

SAXException


WonderWeb