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

java.lang.Object
  extended byedu.stanford.smi.protegex.owl.jena.parser.DefaultURI2NameConverter
All Implemented Interfaces:
URI2NameConverter

public class DefaultURI2NameConverter
extends Object
implements URI2NameConverter

Author:
Holger Knublauch

Field Summary
private static String ANONYMOUS_PREFIX
           
private static String EXTERNAL_RESOURCE_PREFIX
           
private  int externalResourceIndex
           
private  boolean firstDefaultNamespaceHandled
           
private  ProtegeOWLParserLogger logger
           
private  Set ontologyURIs
           
private  OWLModel owlModel
           
private static String PREFIX_BASE
           
private  Map prefix2URI
           
private static String TEMPORARY_PREFIX
           
private  Map uri2Prefix
           
 
Constructor Summary
DefaultURI2NameConverter(OWLModel owlModel, ProtegeOWLParserLogger logger, boolean incremental)
           
 
Method Summary
 String addPrefix(String uri, String prefix)
          Adds a new prefix-namespace pair to this converter.
private  void addPrefixHelper(String uri, String prefix)
           
 String createAnonymousRDFResourceName()
           
 String createNewPrefix(String uri)
          Creates a dummy prefix and adds it to the OWLModel
private  String createNewPrefixHelper(String namespace)
           
private  String getNamespace(String prefix)
           
private  String getPrefix(String uri)
           
 String getRDFExternalResourceName()
           
 String getRDFResourceName(String uri)
          Gets the Protege resource name for a given URI.
 String getResourceNamespace(String uri)
          Gets the namespace part of a resource URI.
 String getTemporaryRDFResourceName(com.hp.hpl.jena.rdf.arp.AResource node)
           
 String getTemporaryRDFResourceName(String uri)
           
 String getURIFromTemporaryName(String temporaryName)
          The inverse of getTemporaryRDFResourceName().
private  void initPrefixesFromOWLModel()
           
 boolean isAnonymousRDFResourceName(String name)
          Checks whether a given name describes an anonymous resource.
protected  boolean isPreferredPrefix(String prefix, String uri)
           
 boolean isTemporaryRDFResourceName(String name)
          Checks if this is a name that was created as a temporary name before.
 void updateInternalState()
          Called after the triples have been copied and new namespace prefixes assigned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

externalResourceIndex

private int externalResourceIndex

firstDefaultNamespaceHandled

private boolean firstDefaultNamespaceHandled

logger

private ProtegeOWLParserLogger logger

owlModel

private OWLModel owlModel

prefix2URI

private Map prefix2URI

uri2Prefix

private Map uri2Prefix

ontologyURIs

private Set ontologyURIs

ANONYMOUS_PREFIX

private static final String ANONYMOUS_PREFIX
See Also:
Constant Field Values

EXTERNAL_RESOURCE_PREFIX

private static final String EXTERNAL_RESOURCE_PREFIX
See Also:
Constant Field Values

TEMPORARY_PREFIX

private static final String TEMPORARY_PREFIX
See Also:
Constant Field Values

PREFIX_BASE

private static final String PREFIX_BASE
See Also:
Constant Field Values
Constructor Detail

DefaultURI2NameConverter

public DefaultURI2NameConverter(OWLModel owlModel,
                                ProtegeOWLParserLogger logger,
                                boolean incremental)
Method Detail

addPrefix

public String addPrefix(String uri,
                        String prefix)
Description copied from interface: URI2NameConverter
Adds a new prefix-namespace pair to this converter. If the namespace is already used under a different prefix then the already existing one will be used and returned. If the prefix is already used for a different namespace, then the prefix will not be used.

Specified by:
addPrefix in interface URI2NameConverter
Parameters:
uri - the URI/namespace
prefix - the new prefix
Returns:
the prefix that will be used for the namespace

addPrefixHelper

private void addPrefixHelper(String uri,
                             String prefix)

createAnonymousRDFResourceName

public String createAnonymousRDFResourceName()
Specified by:
createAnonymousRDFResourceName in interface URI2NameConverter

createNewPrefixHelper

private String createNewPrefixHelper(String namespace)

createNewPrefix

public String createNewPrefix(String uri)
Description copied from interface: URI2NameConverter
Creates a dummy prefix and adds it to the OWLModel

Specified by:
createNewPrefix in interface URI2NameConverter
Parameters:
uri - the URI of the resource to create a new prefix for

getNamespace

private String getNamespace(String prefix)

getPrefix

private String getPrefix(String uri)

getRDFExternalResourceName

public String getRDFExternalResourceName()
Specified by:
getRDFExternalResourceName in interface URI2NameConverter

getRDFResourceName

public String getRDFResourceName(String uri)
Description copied from interface: URI2NameConverter
Gets the Protege resource name for a given URI.

Specified by:
getRDFResourceName in interface URI2NameConverter
Parameters:
uri - the URI to get the name of
Returns:
the Protege name (not null)

getResourceNamespace

public String getResourceNamespace(String uri)
Description copied from interface: URI2NameConverter
Gets the namespace part of a resource URI. This typically wraps the Jena namespace split algorithm.

Specified by:
getResourceNamespace in interface URI2NameConverter
Parameters:
uri - the URI to get the namespace of
Returns:
the namespace (usually including the '#')

getTemporaryRDFResourceName

public String getTemporaryRDFResourceName(String uri)
Specified by:
getTemporaryRDFResourceName in interface URI2NameConverter

getTemporaryRDFResourceName

public String getTemporaryRDFResourceName(com.hp.hpl.jena.rdf.arp.AResource node)
Specified by:
getTemporaryRDFResourceName in interface URI2NameConverter

getURIFromTemporaryName

public String getURIFromTemporaryName(String temporaryName)
Description copied from interface: URI2NameConverter
The inverse of getTemporaryRDFResourceName().

Specified by:
getURIFromTemporaryName in interface URI2NameConverter
Parameters:
temporaryName - the temporary name
Returns:
the URI encoded by the temp name

initPrefixesFromOWLModel

private void initPrefixesFromOWLModel()

isAnonymousRDFResourceName

public boolean isAnonymousRDFResourceName(String name)
Description copied from interface: URI2NameConverter
Checks whether a given name describes an anonymous resource.

Specified by:
isAnonymousRDFResourceName in interface URI2NameConverter
Parameters:
name - the name of the resource to test
Returns:
true if name is an anonymous name

isPreferredPrefix

protected boolean isPreferredPrefix(String prefix,
                                    String uri)

isTemporaryRDFResourceName

public boolean isTemporaryRDFResourceName(String name)
Description copied from interface: URI2NameConverter
Checks if this is a name that was created as a temporary name before. Temporary names should follow a naming convention which keeps them clearly separate from real names.

Specified by:
isTemporaryRDFResourceName in interface URI2NameConverter
Parameters:
name - the name to test
Returns:
true if name is a temporary test

updateInternalState

public void updateInternalState()
Description copied from interface: URI2NameConverter
Called after the triples have been copied and new namespace prefixes assigned. This method must update the internal state of the converter to reflect possible changes during loading (e.g. add new prefixes).

Specified by:
updateInternalState in interface URI2NameConverter