edu.stanford.smi.protegex.owl.jena.parser
Class ProtegeOWLParser

java.lang.Object
  extended byedu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser

public class ProtegeOWLParser
extends Object

An OWL parser that reads an OWL stream triple-by-triple and writes the corresponding Protege-OWL Triples into one or more TripleStores. The current implementation uses the Jena ARP parser for triple loading.

Author:
Holger Knublauch

Nested Class Summary
static interface ProtegeOWLParser.ARPInvokation
          An interface needed as an abstraction of the various methods to invoke the Jena ARP (the various load methods with different parameters).
private  class ProtegeOWLParser.MyErrorHandler
           
private  class ProtegeOWLParser.MyNamespaceHandler
           
private  class ProtegeOWLParser.MyStatementHandler
           
 
Field Summary
private  int count
           
private  String currentDefaultNamespace
          The default namespace to use if the current file does not define one by itself.
private  edu.stanford.smi.protege.model.Frame currentType
           
private static int errorLineNumber
           
private static URI errorURI
           
static boolean inUI
          A rather ugly flag that can be activated to prompt the user if a local file was found as a possible import redirection.
private  boolean isRDFList
           
private  edu.stanford.smi.protege.model.KnowledgeBase kb
           
private  ProtegeOWLParserLogger logger
           
private  OWLModel owlModel
           
private  edu.stanford.smi.protege.model.Cls owlNamedClassClass
           
private  OWLModelPatcher patcher
           
private  String prefixForDefaultNamespace
           
private  RDFProperty rdfFirstProperty
           
private  RDFProperty rdfRestProperty
           
private static String RDFS_RESOURCE_URI
           
private  RDFProperty rdfTypeProperty
           
private  TripleStore tripleStore
           
private  TripleStoreModel tripleStoreModel
           
private  Collection tripleStores
           
private static UnresolvedImportHandler unresolvedImportHandler
           
private  Map untypedResources
           
private  URI2NameConverter uri2NameConverter
           
 
Constructor Summary
ProtegeOWLParser(OWLModel owlModel, boolean incremental)
           
 
Method Summary
static void addImport(JenaOWLModel owlModel, URI ontologyName)
          A convenience method that dynamically adds an import to a JenaOWLModel.
static void addImport(JenaOWLModel owlModel, URI ontologyName, String prefixForDefaultNamespace)
          A convenience method that dynamically adds an import to a JenaOWLModel.
private  void addNamespaceToImports(String defaultNamespace, Set imports)
           
protected  com.hp.hpl.jena.rdf.arp.ARP createARP()
           
private  void createDefaultNamespace(TripleStore tripleStore)
           
private  Object createLiteralObject(com.hp.hpl.jena.rdf.arp.ALiteral node, RDFProperty property)
           
protected  ProtegeOWLParserLogger createLogger()
           
protected  OWLModelPatcher createPatcher()
           
private  RDFResource createRDFResource(String name)
           
private  RDFSLiteral createRDFSLiteral(com.hp.hpl.jena.rdf.arp.ALiteral literal, RDFProperty property)
           
protected  URI2NameConverter createURI2NameConverter(OWLModel owlModel, boolean incremental)
           
private  RDFResource findResource(String name)
           
static int getErrorLineNumber()
           
static URI getErrorURI()
          Gets the URI of the most recently parsed file.
protected  String getImplicitImport(String namespace)
           
static InputStream getInputStream(URL url)
           
protected  ProtegeOWLParserLogger getLogger()
           
private  RDFProperty getRDFProperty(com.hp.hpl.jena.rdf.arp.AResource propertyNode)
           
private  RDFResource getRDFResource(com.hp.hpl.jena.rdf.arp.AResource aResource)
           
private static Repository getRepository(OWLModel owlModel, TripleStore tripleStore, URI ontologyName)
           
private  Collection getUntypedResources()
          Gets all RDFResources that don't have any rdf:type.
 void loadTriples(InputStream is, String xmlBase, TripleStore tripleStore)
           
private  void populateUntypedResourcesMap()
           
private  void replaceNamespace(TripleStore tripleStore, RDFResource ontology, String prefix, String namespace)
           
private  void replaceTemporaryName(TripleStore tripleStore, RDFResource resource, String name, boolean isOntology)
           
private  void replaceTemporaryNames()
           
private  void replaceTemporaryNames(TripleStore tripleStore)
           
 void run(InputStream is, String uri)
           
 void run(Reader reader, String uri)
           
 void run(TripleStore tripleStore, String ontologyName, ProtegeOWLParser.ARPInvokation invokation)
           
 void run(URI uri)
           
 void run(URI uri, String defaultNamespace, TripleStore tripleStore)
          Deprecated.  
 void run(URI uri, TripleStore tripleStore)
           
private  boolean runImplicitImport(RDFResource resource, Set imports, Collection untypedResources)
           
private  boolean runImplicitImports(Set imports)
          Applies some heuristics to resolve missing owl:imports, especially for RDF Schema files.
private  void runImport(String uri, Set imports)
          Imports the ontology that has the name specified by uri.
private  void runImports(TripleStore tripleStore, Set imports)
          Imports the ontologies that are objects of any owl:imports triples in the specified TripleStore.
 void setLogger(ProtegeOWLParserLogger logger)
           
private  void setPrefixForDefaultNamespace(String prefixForDefaultNamespace)
           
static void setUnresolvedImportHandler(UnresolvedImportHandler handler)
           
 void setURI2NameConverter(URI2NameConverter converter)
           
 void setURLResolver(URIResolver urlResolver)
          Deprecated. This method no longer does anything.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

private int count

currentDefaultNamespace

private String currentDefaultNamespace
The default namespace to use if the current file does not define one by itself. This is typically the file's URL (import URI).


currentType

private edu.stanford.smi.protege.model.Frame currentType

errorLineNumber

private static int errorLineNumber

errorURI

private static URI errorURI

inUI

public static boolean inUI
A rather ugly flag that can be activated to prompt the user if a local file was found as a possible import redirection.


isRDFList

private boolean isRDFList

kb

private edu.stanford.smi.protege.model.KnowledgeBase kb

logger

private ProtegeOWLParserLogger logger

owlNamedClassClass

private edu.stanford.smi.protege.model.Cls owlNamedClassClass

owlModel

private OWLModel owlModel

patcher

private OWLModelPatcher patcher

prefixForDefaultNamespace

private String prefixForDefaultNamespace

rdfFirstProperty

private RDFProperty rdfFirstProperty

rdfRestProperty

private RDFProperty rdfRestProperty

RDFS_RESOURCE_URI

private static final String RDFS_RESOURCE_URI

rdfTypeProperty

private RDFProperty rdfTypeProperty

tripleStore

private TripleStore tripleStore

tripleStoreModel

private TripleStoreModel tripleStoreModel

tripleStores

private Collection tripleStores

untypedResources

private Map untypedResources

uri2NameConverter

private URI2NameConverter uri2NameConverter

unresolvedImportHandler

private static UnresolvedImportHandler unresolvedImportHandler
Constructor Detail

ProtegeOWLParser

public ProtegeOWLParser(OWLModel owlModel,
                        boolean incremental)
Method Detail

setUnresolvedImportHandler

public static void setUnresolvedImportHandler(UnresolvedImportHandler handler)

addNamespaceToImports

private void addNamespaceToImports(String defaultNamespace,
                                   Set imports)

addImport

public static void addImport(JenaOWLModel owlModel,
                             URI ontologyName)
                      throws Exception
A convenience method that dynamically adds an import to a JenaOWLModel. This will immediately load the file into a new TripleStore. Prior to invoking this method, the caller should define a prefix for the expected namespace (e.g., URI + "#"). Following the call, the caller should add an import statement to an existing OWLOntology (usually the default ontology).

Parameters:
owlModel -
ontologyName - The name of the imported ontology.
Throws:
Exception

addImport

public static void addImport(JenaOWLModel owlModel,
                             URI ontologyName,
                             String prefixForDefaultNamespace)
                      throws Exception
A convenience method that dynamically adds an import to a JenaOWLModel. This will immediately load the file into a new TripleStore. Following the call, the caller should add an import statement to an existing OWLOntology (usually the default ontology).

Parameters:
owlModel -
ontologyName -
prefixForDefaultNamespace - an (optional) prefix that shall be used for the the default namespace of the directly imported ontology
Throws:
Exception

getRepository

private static Repository getRepository(OWLModel owlModel,
                                        TripleStore tripleStore,
                                        URI ontologyName)

createARP

protected com.hp.hpl.jena.rdf.arp.ARP createARP()

createDefaultNamespace

private void createDefaultNamespace(TripleStore tripleStore)

createLiteralObject

private Object createLiteralObject(com.hp.hpl.jena.rdf.arp.ALiteral node,
                                   RDFProperty property)

createLogger

protected ProtegeOWLParserLogger createLogger()

createPatcher

protected OWLModelPatcher createPatcher()

createRDFSLiteral

private RDFSLiteral createRDFSLiteral(com.hp.hpl.jena.rdf.arp.ALiteral literal,
                                      RDFProperty property)

createRDFResource

private RDFResource createRDFResource(String name)

createURI2NameConverter

protected URI2NameConverter createURI2NameConverter(OWLModel owlModel,
                                                    boolean incremental)

getErrorLineNumber

public static int getErrorLineNumber()

getErrorURI

public static URI getErrorURI()
Gets the URI of the most recently parsed file. This can be used to diagnose where an exception has occured

Returns:
the URI or null

findResource

private RDFResource findResource(String name)

getImplicitImport

protected String getImplicitImport(String namespace)

getLogger

protected ProtegeOWLParserLogger getLogger()

getRDFProperty

private RDFProperty getRDFProperty(com.hp.hpl.jena.rdf.arp.AResource propertyNode)

getRDFResource

private RDFResource getRDFResource(com.hp.hpl.jena.rdf.arp.AResource aResource)

getUntypedResources

private Collection getUntypedResources()
Gets all RDFResources that don't have any rdf:type.

Returns:
the untyped resources

populateUntypedResourcesMap

private void populateUntypedResourcesMap()

replaceNamespace

private void replaceNamespace(TripleStore tripleStore,
                              RDFResource ontology,
                              String prefix,
                              String namespace)

replaceTemporaryNames

private void replaceTemporaryNames()

replaceTemporaryNames

private void replaceTemporaryNames(TripleStore tripleStore)

replaceTemporaryName

private void replaceTemporaryName(TripleStore tripleStore,
                                  RDFResource resource,
                                  String name,
                                  boolean isOntology)

run

public void run(URI uri,
                TripleStore tripleStore)
         throws Exception
Throws:
Exception

loadTriples

public void loadTriples(InputStream is,
                        String xmlBase,
                        TripleStore tripleStore)
                 throws Exception
Throws:
Exception

run

public void run(URI uri,
                String defaultNamespace,
                TripleStore tripleStore)
         throws Exception
Deprecated.  

Throws:
Exception

run

public void run(TripleStore tripleStore,
                String ontologyName,
                ProtegeOWLParser.ARPInvokation invokation)
         throws Exception
Throws:
Exception

runImplicitImports

private boolean runImplicitImports(Set imports)
                            throws IOException,
                                   SAXException
Applies some heuristics to resolve missing owl:imports, especially for RDF Schema files.

Throws:
IOException
SAXException

runImplicitImport

private boolean runImplicitImport(RDFResource resource,
                                  Set imports,
                                  Collection untypedResources)
                           throws SAXException,
                                  IOException
Throws:
SAXException
IOException

runImports

private void runImports(TripleStore tripleStore,
                        Set imports)
                 throws SAXException,
                        IOException
Imports the ontologies that are objects of any owl:imports triples in the specified TripleStore. Ontologies that have already been imported will not be imported again.

Throws:
SAXException
IOException

runImport

private void runImport(String uri,
                       Set imports)
                throws SAXException,
                       IOException
Imports the ontology that has the name specified by uri.

Parameters:
uri - The name of the ontology to be imported.
imports - A Set that contains a list of strings that represent the names of the ontologies that have already been imported.
Throws:
SAXException
IOException

run

public void run(InputStream is,
                String uri)
         throws Exception
Throws:
Exception

run

public void run(Reader reader,
                String uri)
         throws Exception
Throws:
Exception

run

public void run(URI uri)
         throws Exception
Throws:
Exception

setLogger

public void setLogger(ProtegeOWLParserLogger logger)

setPrefixForDefaultNamespace

private void setPrefixForDefaultNamespace(String prefixForDefaultNamespace)

setURI2NameConverter

public void setURI2NameConverter(URI2NameConverter converter)

setURLResolver

public void setURLResolver(URIResolver urlResolver)
Deprecated. This method no longer does anything.


getInputStream

public static InputStream getInputStream(URL url)
                                  throws IOException
Throws:
IOException