info.sswap.impl.empire.model
Class ModelUtils

java.lang.Object
  extended by info.sswap.impl.empire.model.ModelUtils

public class ModelUtils
extends java.lang.Object

Contains utilities to manipulate Jena models as they are read or written by this API.

Author:
Blazej Bulka

Field Summary
static java.lang.String BNODE_NS
          The namespace used for prefixing Jena BNodes.
private static int COMMENTED_OUTPUT_INDENT
          Specifies the identation depth of the generated XML (while commenting RDF/XML)
private static java.util.Set<java.lang.String> KNOWN_URI_SCHEMES
           
private static java.lang.String KNOWN_URI_SCHEMES_FILE
          The file name that contains known URI schemes registered by IANA (so that we can distinguish a use of an undefined namespace from a valid URI with an unusual scheme).
private static int MAX_REDIRECTS
          A constant specifying how many redirects an invocation of a RIG/RQG should be allowed before giving up (e.g., because the redirects may be an infinite loop).
private static com.hp.hpl.jena.rdf.model.Resource[] PRETTY_TYPES
          Constant for name of types that will be passed as "prettyTypes" to Jena.
private static com.hp.hpl.jena.rdf.model.Resource[] SSWAP_NODE_TYPES
          Types of SSWAPNodes (resources that require special handling in SSWAP Protocol)
private static java.lang.String SSWAP_PROTOCOL_COMMENTS_STYLESHEET
          The file name of the XSL StyleSheet that adds comments to an RDF/XML serialization of a SSWAP protocol graph
 
Constructor Summary
ModelUtils()
           
 
Method Summary
private static void addImportStatements(com.hp.hpl.jena.rdf.model.Model originalModel, com.hp.hpl.jena.rdf.model.Model partitionedModel)
          Copies all import statements from the original model.
private static void addStatementsToPartitionedModel(com.hp.hpl.jena.rdf.model.Resource resource, com.hp.hpl.jena.rdf.model.Model originalModel, com.hp.hpl.jena.rdf.model.Model partitionedModel, java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> alreadyAdded, boolean followAllResources)
          Copies statements that only relate to a specific resource.
private static void addTypeStatements(com.hp.hpl.jena.rdf.model.Resource resource, com.hp.hpl.jena.rdf.model.Model originalModel, com.hp.hpl.jena.rdf.model.Model partitionedModel)
           
private static void commentRdfXmlProtocolGraph(java.io.InputStream is, java.io.OutputStream os)
          Adds XML comments to RDF/XML representation of a sswap protocol graph.
private static int connect(java.net.HttpURLConnection httpConn, byte[] inputBytes)
           
private static java.lang.String convert(com.hp.hpl.jena.rdf.model.RDFNode node)
           
private static com.hp.hpl.jena.rdf.model.Resource convertBNode(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource resource)
          Converts a bnode resource into a non-bnode resource (by generating a URI that belongs to a reserved namespace).
private static java.lang.String convertBNodeId(java.lang.String anonId)
          Converts an identifier of an anonymous node (AnonId) into a valid URI in the special, reserved namespace that will later be used to convert that node back into a bnode (during serialization)
static void convertSSWAPNodesToBNodes(com.hp.hpl.jena.rdf.model.Model model)
          Converts all SSWAP nodes (nodes that require special handling in SSWAP protocol; e.g., sswap:Resource) to BNodes (or more exactly to nodes named using the special BNode naming scheme).
private static void convertToBNodes(java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> resources)
          Converts a given set of resources to BNodes (i.e., resources named using the BNode naming scheme)
private static void convertToOWLOntology(org.semanticweb.owlapi.model.OWLOntology ontology, com.hp.hpl.jena.rdf.model.Model... models)
           
private static com.hp.hpl.jena.rdf.model.Model createOutputModel(com.hp.hpl.jena.rdf.model.Model model)
          Creates a model that is suitable for writing out using Jena Writers.
static org.semanticweb.owlapi.model.OWLOntology createOWLOntology(org.semanticweb.owlapi.model.OWLOntologyManager manager, java.lang.String url, com.hp.hpl.jena.rdf.model.Model model)
           
static org.semanticweb.owlapi.model.OWLOntology createOWLOntology(org.semanticweb.owlapi.model.OWLOntologyManager manager, java.lang.String url, com.hp.hpl.jena.rdf.model.Model baseModel, com.hp.hpl.jena.rdf.model.Model closure)
           
static com.hp.hpl.jena.rdf.model.RDFList createRDFList(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource listResource)
          Creates an RDFList object based on the rdf:List data in the underlying Jena model.
static com.clarkparsia.utils.web.Response executeRequest(java.net.URLConnection requestConn)
          Executes the HTTP request associated with the given connection without any input.
static com.clarkparsia.utils.web.Response executeRequest(java.net.URLConnection requestConn, java.io.InputStream requestBody)
          Executes the HTTP request associated with the given connection with the given input which may be null.
private static com.clarkparsia.utils.web.Response executeRequest(java.net.URLConnection requestConn, java.io.InputStream requestBody, boolean returnOnHTTPError)
          Executes the HTTP request associated with the given connection with the given input which may be null.
private static void forEachResource(com.hp.hpl.jena.rdf.model.Model model, com.google.common.base.Function<com.hp.hpl.jena.rdf.model.Resource,java.lang.Void> function)
          Applies a function to each resource in the model that is mentioned as a subject or an object in any statement in the model.
static java.lang.String generateBNodeId()
           
static java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> getAllResourcesForList(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource listResource)
          Gets all resources involved in an rdf:List.
static java.util.Collection<com.hp.hpl.jena.rdf.model.Statement> getAllStatementsForList(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource listResource)
          Gets all Jena Statements that encode an RDFList
static com.hp.hpl.jena.rdf.model.RDFNode getFirstObjectValue(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource subject, com.hp.hpl.jena.rdf.model.Property predicate)
          A utility method for extracting the first encountered value in the object position for the given resource and predicate.
static com.hp.hpl.jena.rdf.model.Statement getFirstStatement(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource subject, com.hp.hpl.jena.rdf.model.Property predicate)
          Gets the first encountered statement for the with the given resource in the subject position and the predicate
private static int getInvocationTimeout()
           
private static java.io.InputStream getKnownURISchemesStream()
           
private static com.hp.hpl.jena.rdf.model.Resource getListHead(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource listNode)
          Gets a head of a list for a given internal node (not a list member!)
static java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> getListURIs(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource listMember)
          Gets the URIs of all lists the given resource is a member
private static java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> getResourcesByType(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource typeResource)
          Gets all resources that have the specified type (via rdf:type property)
static java.util.Collection<java.lang.String> getResourcesInNS(com.hp.hpl.jena.rdf.model.Model model, java.lang.String ns)
          Gets URIs of all resources in the model that belong to the specified namespace
private static java.io.InputStream getSSWAPProtocolCommentsXsltStream()
          Opens a stream that leads to an XSL style sheet that adds comments to a sswap protocol graph
static java.util.Collection<java.lang.String> getTermsWithoutValidScheme(com.hp.hpl.jena.rdf.model.Model model)
          Gets the terms in the model whose URIs do not have a valid scheme (i.e., registered by IANA).
private static boolean hasDeclaredType(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource resource, com.hp.hpl.jena.rdf.model.Resource type)
          Checks whether a resource has a certain declared (rdf:type) type.
static boolean hasKnownScheme(java.lang.String uriString)
          Checks whether the URI has a known scheme (i.e., registered by IANA).
private static java.net.HttpURLConnection httpConn(java.net.URL url)
          Creates a new HTTP connection for the given URL.
private static java.net.HttpURLConnection httpConn(java.net.URLConnection conn)
          Casts the given connection to an HTTP connection
private static java.net.HttpURLConnection httpConn(java.net.URL url, java.net.HttpURLConnection conn, java.util.Map<java.lang.String,java.util.List<java.lang.String>> props)
          Creates a new HTTP connection for the given URL and copies the settings from the given connection and request properties.
static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI)
          Convenience method to invoke(URI invocationURI, InputStream graphContentsStream) to execute a HTTP GET.
static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI, byte[] graphContentsArray)
          Convenience method to invoke(URI invocationURI, InputStream graphContentsStream) to execute a HTTP POST with array data as the body of the POST.
static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI, java.io.InputStream graphContentsStream)
          Invokes HTTP GET or POST to URL.
static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI, java.io.InputStream graphContentsStream, boolean returnOnHTTPError)
          Invokes HTTP GET or POST to URL.
static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI, java.io.InputStream graphContentsStream, boolean returnOnHTTPError, long timeout)
          Invokes HTTP GET or POST to URL.
static boolean isBNodeURI(java.lang.String bnodeURI)
           
static boolean isSchemeKnown(java.lang.String scheme)
          Checks whether the scheme is a known URI scheme (i.e., registered by IANA)
static java.lang.String normalizeURI(java.lang.String uriStr)
          Trims the #fragment identifier from a URI string to allow subsequent matching on the URI string minus any fragment identifier.
static com.hp.hpl.jena.rdf.model.Model partitionModel(com.hp.hpl.jena.rdf.model.Model originalModel, java.lang.String uri, boolean followAllResources)
          Extracts from the original Jena Model facts that relate only to the specified individual.
private static java.util.Set<java.lang.String> readKnownURISchemes()
           
static void removeBNodes(com.hp.hpl.jena.rdf.model.Model model)
          Removes BNodes from a model by converting them into a resource with a URI (which belongs to a reserved namespace).
private static void removeBNodes(com.hp.hpl.jena.rdf.model.Model model, java.util.Iterator<? extends com.hp.hpl.jena.rdf.model.RDFNode> it)
          Removes BNodes from a Node iterator by converting them into a resource with a URI (which belongs to a reserved namespace).
static void serializeModel(com.hp.hpl.jena.rdf.model.Model model, java.io.OutputStream os, RDFRepresentation rdfRepresentation, boolean commentedOutput)
          Serializes a Jena model into the output stream in the specified RDF representation.
private static boolean shouldRemainAnon(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource resource)
          Checks whether a resource should remain anonymous.
static void validateSSWAPVocabulary(com.hp.hpl.jena.rdf.model.Model model)
          Validates whether all resources in SSWAP namespace used in the model are defined in SSWAP ontology.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SSWAP_PROTOCOL_COMMENTS_STYLESHEET

private static final java.lang.String SSWAP_PROTOCOL_COMMENTS_STYLESHEET
The file name of the XSL StyleSheet that adds comments to an RDF/XML serialization of a SSWAP protocol graph

See Also:
Constant Field Values

KNOWN_URI_SCHEMES_FILE

private static final java.lang.String KNOWN_URI_SCHEMES_FILE
The file name that contains known URI schemes registered by IANA (so that we can distinguish a use of an undefined namespace from a valid URI with an unusual scheme).

See Also:
Constant Field Values

KNOWN_URI_SCHEMES

private static java.util.Set<java.lang.String> KNOWN_URI_SCHEMES

COMMENTED_OUTPUT_INDENT

private static final int COMMENTED_OUTPUT_INDENT
Specifies the identation depth of the generated XML (while commenting RDF/XML)

See Also:
Constant Field Values

BNODE_NS

public static final java.lang.String BNODE_NS
The namespace used for prefixing Jena BNodes. Empire has problem handling Java BNodes for multiple reasons. First, it may be difficult to distinguish a bnode id from a URI by looking just at identifier (this happens in situations where there is no access to a Jena Resource; e.g., while evaluating SPARQL queries) -- there is an overlap in valid bnode syntax and URI syntax. Second, when a bnode id is mistaken for a URI, Empire internals may complain that it is not an absolute URI. To solve this problems, all loaded Jena models have (almost all) their bnodes filtered and replaced with regular resources whose URIs belong to this specific, reserved namespace (i.e., no bnodes). When serializing the model out, all such resources can be easily identified (only these resources belong to this namespace), and can be properly converted back to a bnode. The only bnodes that are not filtered on the load are certain nodes in OWL2 expressions, and where determined to cause problems with reasoning if converted to named resources. An example of such a bnode is currently a bnode typed as DataRange. (But there may be others, since OWL2 actually requires the use of bnodes in certain places, although reasoners can typically handle named resources in such places OK because of compatibility with OWL1, which did not have such a restriction.)

See Also:
Constant Field Values

MAX_REDIRECTS

private static int MAX_REDIRECTS
A constant specifying how many redirects an invocation of a RIG/RQG should be allowed before giving up (e.g., because the redirects may be an infinite loop).


SSWAP_NODE_TYPES

private static final com.hp.hpl.jena.rdf.model.Resource[] SSWAP_NODE_TYPES
Types of SSWAPNodes (resources that require special handling in SSWAP Protocol)


PRETTY_TYPES

private static final com.hp.hpl.jena.rdf.model.Resource[] PRETTY_TYPES
Constant for name of types that will be passed as "prettyTypes" to Jena. This will be a suggestion to Jena RDF/XML-ABBREV writer to create RDF/XML withe resources of these types at the top level.

Constructor Detail

ModelUtils

public ModelUtils()
Method Detail

serializeModel

public static void serializeModel(com.hp.hpl.jena.rdf.model.Model model,
                                  java.io.OutputStream os,
                                  RDFRepresentation rdfRepresentation,
                                  boolean commentedOutput)
Serializes a Jena model into the output stream in the specified RDF representation. Since internally, this API removed all the BNodes (by renaming them with generated identifiers that belong to a special namespace), this method renames such previously renamed nodes back into bnodes. Additionally, this method can produce a commented output (e.g., for educational purposes) of the RDG (only RDF/XML representation); i.e., it will contain XML comments describing parts of the protocol graph.

Parameters:
model - the Jena model to be serialized
os - the output stream to which the model should be serialized
rdfRepresentation - the RDF representation in which the model should be serialized
commentedOutput - true, if the RDF/XML output should be commented, false otherwise (this flag is ignored for outputs other than RDF/XML, and should only be used for protocol graphs).

commentRdfXmlProtocolGraph

private static void commentRdfXmlProtocolGraph(java.io.InputStream is,
                                               java.io.OutputStream os)
                                        throws javax.xml.transform.TransformerException,
                                               java.io.IOException
Adds XML comments to RDF/XML representation of a sswap protocol graph. The comments are added by performing an XSLT transformation of the original RDF/XML data (the XSLT stylesheet specifies which comments are added and where). Current implementation uses the stylesheet that is returned by getSSWAPProtocolCommentsXsltStream().

Parameters:
is - the input stream from which the data for commenting is read.
os - the output stream to which the commented data is written
Throws:
javax.xml.transform.TransformerException - if an exception occurs during the XSLT transformation
java.io.IOException - if an I/O error should occur

getSSWAPProtocolCommentsXsltStream

private static java.io.InputStream getSSWAPProtocolCommentsXsltStream()
                                                               throws java.io.FileNotFoundException
Opens a stream that leads to an XSL style sheet that adds comments to a sswap protocol graph

Returns:
the stream that contains the XSL style sheet
Throws:
java.io.FileNotFoundException - if the underlying XSL data cannot be found

getKnownURISchemesStream

private static java.io.InputStream getKnownURISchemesStream()
                                                     throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

readKnownURISchemes

private static java.util.Set<java.lang.String> readKnownURISchemes()
                                                            throws java.io.IOException
Throws:
java.io.IOException

isSchemeKnown

public static boolean isSchemeKnown(java.lang.String scheme)
Checks whether the scheme is a known URI scheme (i.e., registered by IANA)

Parameters:
scheme - the scheme to be checked
Returns:
true if the scheme is a registered scheme, false otherwise

hasKnownScheme

public static boolean hasKnownScheme(java.lang.String uriString)
Checks whether the URI has a known scheme (i.e., registered by IANA).

Parameters:
uriString - string containing a URI
Returns:
true, if the string is a valid URI and it has a scheme that is known, false otherwise (i.e., scheme is not known or the string is not a valid URI, and therefore has no scheme).

getTermsWithoutValidScheme

public static java.util.Collection<java.lang.String> getTermsWithoutValidScheme(com.hp.hpl.jena.rdf.model.Model model)
Gets the terms in the model whose URIs do not have a valid scheme (i.e., registered by IANA). Most likely such terms are just QNames whose namespace prefixes did not get expanded properly (e.g., a particular prefix was not defined).

Parameters:
model - Jena model that should be checked for terms without a valid scheme
Returns:
a collection of terms (strings containing URIs of terms) with all terms that do not have a valid scheme

removeBNodes

public static void removeBNodes(com.hp.hpl.jena.rdf.model.Model model)
Removes BNodes from a model by converting them into a resource with a URI (which belongs to a reserved namespace).

Parameters:
model - the model from which all bnodes should be removed

convertSSWAPNodesToBNodes

public static void convertSSWAPNodesToBNodes(com.hp.hpl.jena.rdf.model.Model model)
Converts all SSWAP nodes (nodes that require special handling in SSWAP protocol; e.g., sswap:Resource) to BNodes (or more exactly to nodes named using the special BNode naming scheme).

Parameters:
model - the model whose SSWAP nodes should be converted to BNodes

convertToBNodes

private static void convertToBNodes(java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> resources)
Converts a given set of resources to BNodes (i.e., resources named using the BNode naming scheme)

Parameters:
resources - the resources to be converted

getResourcesByType

private static java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> getResourcesByType(com.hp.hpl.jena.rdf.model.Model model,
                                                                                           com.hp.hpl.jena.rdf.model.Resource typeResource)
Gets all resources that have the specified type (via rdf:type property)

Parameters:
model - the model where the resources are
typeResource - the resource describing the type
Returns:
a collection of all resources that are of the specified type

removeBNodes

private static void removeBNodes(com.hp.hpl.jena.rdf.model.Model model,
                                 java.util.Iterator<? extends com.hp.hpl.jena.rdf.model.RDFNode> it)
Removes BNodes from a Node iterator by converting them into a resource with a URI (which belongs to a reserved namespace).

Parameters:
model - the model from which all bnodes should be removed
it - the iterator

shouldRemainAnon

private static boolean shouldRemainAnon(com.hp.hpl.jena.rdf.model.Model model,
                                        com.hp.hpl.jena.rdf.model.Resource resource)
Checks whether a resource should remain anonymous. Some bnodes that belong to OWL2 expressions should remain anonymous, or they will cause problems with reasoning. Currently, the only type of bnodes that remain anonymous are those typed (rdf:type) as owl:DataRange

Parameters:
model - the model to which the resource belongs
resource - the resource to be checked
Returns:
true if the resource should remain anonymous, false if it can safely be converted to a named resource

hasDeclaredType

private static boolean hasDeclaredType(com.hp.hpl.jena.rdf.model.Model model,
                                       com.hp.hpl.jena.rdf.model.Resource resource,
                                       com.hp.hpl.jena.rdf.model.Resource type)
Checks whether a resource has a certain declared (rdf:type) type.

Parameters:
model - model to which the resource belongs
resource - the resource to be checked
type - the type to which the resource should belong
Returns:
true if a triple resource rdf:type type exists in the model, false otherwise

convertBNode

private static com.hp.hpl.jena.rdf.model.Resource convertBNode(com.hp.hpl.jena.rdf.model.Model model,
                                                               com.hp.hpl.jena.rdf.model.Resource resource)
Converts a bnode resource into a non-bnode resource (by generating a URI that belongs to a reserved namespace).

Parameters:
model - the model to which this resource belongs
resource - the bnode resource
Returns:
the new resource after renaming
Throws:
java.lang.IllegalArgumentException - if the resource is not a bnode resource

convertBNodeId

private static java.lang.String convertBNodeId(java.lang.String anonId)
Converts an identifier of an anonymous node (AnonId) into a valid URI in the special, reserved namespace that will later be used to convert that node back into a bnode (during serialization)

Parameters:
anonId - anonymous node (blank node) id
Returns:
a valid URI to be used as the id

generateBNodeId

public static java.lang.String generateBNodeId()

isBNodeURI

public static boolean isBNodeURI(java.lang.String bnodeURI)

createOutputModel

private static com.hp.hpl.jena.rdf.model.Model createOutputModel(com.hp.hpl.jena.rdf.model.Model model)
Creates a model that is suitable for writing out using Jena Writers. It copies all the statements in the given model, sets up namespace prefixes, and handles bnodes that were converted into URIs when the data was read in.

Parameters:
model - the source model for the new model
Returns:
the model that has been processed for writing.

forEachResource

private static void forEachResource(com.hp.hpl.jena.rdf.model.Model model,
                                    com.google.common.base.Function<com.hp.hpl.jena.rdf.model.Resource,java.lang.Void> function)
Applies a function to each resource in the model that is mentioned as a subject or an object in any statement in the model.

Parameters:
model - the model that contains the resources
function - the function that should be applied

getFirstObjectValue

public static com.hp.hpl.jena.rdf.model.RDFNode getFirstObjectValue(com.hp.hpl.jena.rdf.model.Model model,
                                                                    com.hp.hpl.jena.rdf.model.Resource subject,
                                                                    com.hp.hpl.jena.rdf.model.Property predicate)
A utility method for extracting the first encountered value in the object position for the given resource and predicate. This method is generally used for properties for which it is expected that at most one value exists.

Parameters:
model - the model from which the value should be extracted
subject - the subject for which the value should be extracted
predicate - the predicate for which the value should be extracted
Returns:
the rdf node for the first encountered value or null, if no value was encountered

getFirstStatement

public static com.hp.hpl.jena.rdf.model.Statement getFirstStatement(com.hp.hpl.jena.rdf.model.Model model,
                                                                    com.hp.hpl.jena.rdf.model.Resource subject,
                                                                    com.hp.hpl.jena.rdf.model.Property predicate)
Gets the first encountered statement for the with the given resource in the subject position and the predicate

Parameters:
model - model that should contain the statement
subject - the subject of the requested statement
predicate - the predicate for the statement
Returns:
the statement (first encountered one if there are multiple ones), or null if none could be encountered

getListURIs

public static java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> getListURIs(com.hp.hpl.jena.rdf.model.Model model,
                                                                                   com.hp.hpl.jena.rdf.model.Resource listMember)
Gets the URIs of all lists the given resource is a member

Parameters:
model - model where the resource is located
listMember - a (potential) member of some lists (not an internal node within a list!)
Returns:
collection of the first resources in every list, listMember is member of

getListHead

private static com.hp.hpl.jena.rdf.model.Resource getListHead(com.hp.hpl.jena.rdf.model.Model model,
                                                              com.hp.hpl.jena.rdf.model.Resource listNode)
Gets a head of a list for a given internal node (not a list member!)

Parameters:
model - model where the node is located
listNode - the list node for the list
Returns:
the list head (may be the same as listNode, if listNode is a head) or null, if listNode is not in fact a list node

createRDFList

public static com.hp.hpl.jena.rdf.model.RDFList createRDFList(com.hp.hpl.jena.rdf.model.Model model,
                                                              com.hp.hpl.jena.rdf.model.Resource listResource)
                                                       throws java.lang.IllegalArgumentException
Creates an RDFList object based on the rdf:List data in the underlying Jena model.

Parameters:
model - the model containing the data describing the list
listResource - the resource containing the head of the list
Returns:
the RDFList with the data
Throws:
java.lang.IllegalArgumentException - if the underlying data does not form a well-formed list

getAllStatementsForList

public static java.util.Collection<com.hp.hpl.jena.rdf.model.Statement> getAllStatementsForList(com.hp.hpl.jena.rdf.model.Model model,
                                                                                                com.hp.hpl.jena.rdf.model.Resource listResource)
Gets all Jena Statements that encode an RDFList

Parameters:
model - the model with the Jena Statements
listResource - the first resource of the list
Returns:
a collection of statements that make up that list

getAllResourcesForList

public static java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> getAllResourcesForList(com.hp.hpl.jena.rdf.model.Model model,
                                                                                              com.hp.hpl.jena.rdf.model.Resource listResource)
Gets all resources involved in an rdf:List. This includes all the intermediate nodes (connected via rdf:rest predicates), with the exception of the terminating rdf:nil. The rationale for introducing this method is the need to properly remove all the statements relating to a list when the list itself should be removed.

Parameters:
model - the model containing the list data
listResource - the resource that is the head of the list
Returns:
a collection of all resources involved in RDF serialization of this list (including the intermediate nodes connected by rdf:rest, but not including rdf:nil)

partitionModel

public static com.hp.hpl.jena.rdf.model.Model partitionModel(com.hp.hpl.jena.rdf.model.Model originalModel,
                                                             java.lang.String uri,
                                                             boolean followAllResources)
Extracts from the original Jena Model facts that relate only to the specified individual. Additionally, this method also copies all owl:imports statements so that all the classes in the produced model are properly declared.

Parameters:
originalModel - the model containing all the facts
uri - the URI of the individual
Returns:
the sub model that contains only the facts that relate to this individual

addStatementsToPartitionedModel

private static void addStatementsToPartitionedModel(com.hp.hpl.jena.rdf.model.Resource resource,
                                                    com.hp.hpl.jena.rdf.model.Model originalModel,
                                                    com.hp.hpl.jena.rdf.model.Model partitionedModel,
                                                    java.util.Collection<com.hp.hpl.jena.rdf.model.Resource> alreadyAdded,
                                                    boolean followAllResources)
Copies statements that only relate to a specific resource. This method copies all the statements where this resource is a subject. Moreover, if any of that statements refers to a bnode, all the statements for that bnode will also be included.

Parameters:
resource - the resource for which statements should be copied.
originalModel - the original model that contains all the statements
partitionedModel - the partitioned model being created
alreadyAdded - a collection of the resources that were already processed (to speed up the process, in case some resources are referenced multiple times).

addTypeStatements

private static void addTypeStatements(com.hp.hpl.jena.rdf.model.Resource resource,
                                      com.hp.hpl.jena.rdf.model.Model originalModel,
                                      com.hp.hpl.jena.rdf.model.Model partitionedModel)

addImportStatements

private static void addImportStatements(com.hp.hpl.jena.rdf.model.Model originalModel,
                                        com.hp.hpl.jena.rdf.model.Model partitionedModel)
Copies all import statements from the original model.

Parameters:
originalModel - the model from which the import statements should be copied
partitionedModel - the model to which the import statements should be copied

createOWLOntology

public static org.semanticweb.owlapi.model.OWLOntology createOWLOntology(org.semanticweb.owlapi.model.OWLOntologyManager manager,
                                                                         java.lang.String url,
                                                                         com.hp.hpl.jena.rdf.model.Model model)
                                                                  throws org.semanticweb.owlapi.model.OWLOntologyCreationException
Throws:
org.semanticweb.owlapi.model.OWLOntologyCreationException

createOWLOntology

public static org.semanticweb.owlapi.model.OWLOntology createOWLOntology(org.semanticweb.owlapi.model.OWLOntologyManager manager,
                                                                         java.lang.String url,
                                                                         com.hp.hpl.jena.rdf.model.Model baseModel,
                                                                         com.hp.hpl.jena.rdf.model.Model closure)
                                                                  throws org.semanticweb.owlapi.model.OWLOntologyCreationException
Throws:
org.semanticweb.owlapi.model.OWLOntologyCreationException

convertToOWLOntology

private static void convertToOWLOntology(org.semanticweb.owlapi.model.OWLOntology ontology,
                                         com.hp.hpl.jena.rdf.model.Model... models)
                                  throws org.semanticweb.owlapi.model.OWLOntologyCreationException
Throws:
org.semanticweb.owlapi.model.OWLOntologyCreationException

convert

private static java.lang.String convert(com.hp.hpl.jena.rdf.model.RDFNode node)

getResourcesInNS

public static java.util.Collection<java.lang.String> getResourcesInNS(com.hp.hpl.jena.rdf.model.Model model,
                                                                      java.lang.String ns)
Gets URIs of all resources in the model that belong to the specified namespace

Parameters:
model - the model whose resources are to be returned
ns - the namespace URI
Returns:
a collection of URIs of resources that belong to the specified namespace

validateSSWAPVocabulary

public static void validateSSWAPVocabulary(com.hp.hpl.jena.rdf.model.Model model)
                                    throws ValidationException
Validates whether all resources in SSWAP namespace used in the model are defined in SSWAP ontology. (The use of SSWAP namespace is restricted, similarly to OWL namespace; only terms defined in SSWAP ontology can be used in other models.)

Parameters:
model - the model to be validated
Throws:
ValidationException - if the model contains a resource from SSWAP namespace that is not defined in SSWAP ontology.

invoke

public static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI)
                                                 throws java.io.IOException
Convenience method to invoke(URI invocationURI, InputStream graphContentsStream) to execute a HTTP GET.

Parameters:
invocationURI - URI to invoke (upon successful conversion of URI to a URL)
Returns:
the response of the invocation attempt
Throws:
java.io.IOException - on any failure to execute call, including HTTP response codes of 400- or 500- series
See Also:
invoke(URI,InputStream,boolean)

invoke

public static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI,
                                                        byte[] graphContentsArray)
                                                 throws java.io.IOException
Convenience method to invoke(URI invocationURI, InputStream graphContentsStream) to execute a HTTP POST with array data as the body of the POST.

Parameters:
invocationURI - URI to invoke (upon successful conversion of URI to a URL)
graphContentsArray - contents of a HTTP POST; set to null to invoke HTTP GET
Returns:
the response of the invocation attempt
Throws:
java.io.IOException - on any failure to execute call, including HTTP response codes of 400- or 500- series
See Also:
invoke(URI,InputStream,boolean)

invoke

public static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI,
                                                        java.io.InputStream graphContentsStream)
                                                 throws java.io.IOException
Invokes HTTP GET or POST to URL. Access to the invocation response content can be gained by calling getContent on the returned response.

Parameters:
invocationURI - URI to invoke (upon successful conversion of URI to a URL)
graphContentsStream - contents of a HTTP POST; set to null to invoke HTTP GET
Returns:
the response of the invocation attempt
Throws:
java.io.IOException - on any failure to execute call, including HTTP response codes of 400- or 500- series
See Also:
invoke(URI,InputStream,boolean)

invoke

public static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI,
                                                        java.io.InputStream graphContentsStream,
                                                        boolean returnOnHTTPError)
                                                 throws java.io.IOException
Invokes HTTP GET or POST to URL. Access to the invocation response content can be gained by calling getContent on the returned response.

Parameters:
invocationURI - URI to invoke (upon successful conversion of URI to a URL)
graphContentsStream - contents of a HTTP POST; set to null to invoke HTTP GET
returnOnHTTPError - if true, HTTP error response codes (e.g., 400- or 500- series will not result in a thrown exception; returned response object may be examined
Returns:
the response of the invocation attempt
Throws:
java.io.IOException - on any failure to execute call

invoke

public static com.clarkparsia.utils.web.Response invoke(java.net.URI invocationURI,
                                                        java.io.InputStream graphContentsStream,
                                                        boolean returnOnHTTPError,
                                                        long timeout)
                                                 throws java.io.IOException
Invokes HTTP GET or POST to URL. Access to the invocation response content can be gained by calling getContent on the returned response.

Parameters:
invocationURI - URI to invoke (upon successful conversion of URI to a URL)
graphContentsStream - contents of a HTTP POST; set to null to invoke HTTP GET
returnOnHTTPError - if true, HTTP error response codes (e.g., 400- or 500- series will not result in a thrown exception; returned response object may be examined
timeout - connect and read timeout in milliseconds
Returns:
the response of the invocation attempt
Throws:
java.io.IOException - on any failure to execute call

httpConn

private static java.net.HttpURLConnection httpConn(java.net.URLConnection conn)
                                            throws java.lang.IllegalArgumentException
Casts the given connection to an HTTP connection

Throws:
java.lang.IllegalArgumentException - if the given connection is not an HTTP connection

httpConn

private static java.net.HttpURLConnection httpConn(java.net.URL url)
                                            throws java.io.IOException
Creates a new HTTP connection for the given URL.

Throws:
java.io.IOException

httpConn

private static java.net.HttpURLConnection httpConn(java.net.URL url,
                                                   java.net.HttpURLConnection conn,
                                                   java.util.Map<java.lang.String,java.util.List<java.lang.String>> props)
                                            throws java.io.IOException
Creates a new HTTP connection for the given URL and copies the settings from the given connection and request properties.

Throws:
java.io.IOException

executeRequest

public static com.clarkparsia.utils.web.Response executeRequest(java.net.URLConnection requestConn)
                                                         throws java.io.IOException
Executes the HTTP request associated with the given connection without any input.

Parameters:
requestConn -
Returns:
a response object
Throws:
java.io.IOException - if an exception occurs or the HTTP response code indicates an error

executeRequest

public static com.clarkparsia.utils.web.Response executeRequest(java.net.URLConnection requestConn,
                                                                java.io.InputStream requestBody)
                                                         throws java.io.IOException
Executes the HTTP request associated with the given connection with the given input which may be null.

Parameters:
requestConn - URL connection
requestBody - input to the request
Returns:
a response object
Throws:
java.io.IOException - if an exception occurs or the HTTP response code indicates an error

connect

private static int connect(java.net.HttpURLConnection httpConn,
                           byte[] inputBytes)
                    throws java.io.IOException
Throws:
java.io.IOException

executeRequest

private static com.clarkparsia.utils.web.Response executeRequest(java.net.URLConnection requestConn,
                                                                 java.io.InputStream requestBody,
                                                                 boolean returnOnHTTPError)
                                                          throws java.io.IOException
Executes the HTTP request associated with the given connection with the given input which may be null.

Parameters:
requestConn - URL connection
requestBody - input to the request
returnOnHTTPError - if false an exception is thrown if the response code indicates an error
Returns:
a response object
Throws:
java.io.IOException - if an exception occurs or the HTTP response code indicates an error and returnOnHTTPError is false

getInvocationTimeout

private static int getInvocationTimeout()

normalizeURI

public static java.lang.String normalizeURI(java.lang.String uriStr)
Trims the #fragment identifier from a URI string to allow subsequent matching on the URI string minus any fragment identifier.

Note: experience shows that query strings (part of the URI following a '?') are often encountered, so future modifications to this method should not ignore the query string, if any.

Parameters:
uriStr - original full URI string (w/ fragment identifier, if any)
Returns:
URI string minus any fragment identifier; returns null if an appropriate URI transformation cannot be constructed


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.