Ontology Manager
The newest version of ontology manager code can be found at ASTRA repository: http://basar.idi.ntnu.no/svn/astra/CODE/Components/OntologyManager . A compiled OSGi bundle is at http://basar.idi.ntnu.no/svn/astra/CODE/Components/OntologyManager/build/jar/OntologyManagerbundle.jar
What is it?
It is a bundle that offers an API for interacting with the ASTRA ontologies.
Current functionalities
- Generic SPARQL ontology querying interface
- Generic Ontology updating interface using a custom SQL like syntax
- Specialized methods for interacting with other ASTRA Components
Interface
ArrayList getClassNames([ResultPrefixType ptype[, String defaultPrefix]])
- Returns the names of all the classes declared in the ontology model. Parameters:
ResultPrefixType ptype [Optional]: Names Prefixing type. Controls the way the returned names are prefixed depending on the XML namespace they belong to. For available options see OntologyManager/ResultPrefixType. Default is no prefixing (OntologyManager.ResultPrefixType.PREFIX_SKIP_ALL).
- String defaultPrefix [Optional]: If ptype parameter is present, defaultPrefix declares the namespace that is considered default for this call.
The names belonging to defaultPrefix namespace will or will not be prefixed with it, depending on ptype parameter . Names belonging to other namespaces may or may not be prefixed depending on ptype parameter (see OntologyManager/ResultPrefixType). defaultPrefix may be in URI format (eg. "http://my.domain/MyOntology.owl#" - Note that URIs mast end with #), or a known short prefix name (e.g. "location") If not specified the default prefix is the default xml namespace declared into the ontology XML/OWL code (xmlns and xml:base).
ArrayList getResourcesByClass(String className, boolean includesubs [, ResultPrefixType ptype [, String defaultPrefix]])
- Returns all the owl individuals belonging to the class className. Parameters:
- String className: The name of the class. The name can be prefixed in full or short form. If it is not prefixed and defaultPrefix parameter is given the name is prefixed with this prefix. If the name is not prefixed and no defaultPrefix is given the ontology default namespace prefix is assumed.
- boolean includesubs: if True then the individuals belonging in subclasses of the class defined by className will be returned. If false only direct individuals of the class className will be returned.
ResultPrefixType ptype [Optional]: Names Prefixing type. Controls the way the returned names are prefixed depending on the XML namespace they belong to. For available options see OntologyManager/ResultPrefixType. Default is no prefixing (OntologyManager.ResultPrefixType.PREFIX_SKIP_ALL).
- String defaultPrefix [Optional]: If ptype parameter is present, defaultPrefix declares the namespace that is considered default for this call.
The names belonging to defaultPrefix namespace will or will not be prefixed with it, depending on ptype parameter. Names belonging to other namespaces may or may not be prefixed depending on ptype parameter (see OntologyManager/ResultPrefixType). defaultPrefix may be in URI format (eg. "http://my.domain/MyOntology.owl#" - Note that URIs mast end with #), or a known short prefix name (e.g. "location") If not specified the default prefix is the default xml namespace declared into the ontology XML/OWL code (xmlns and xml:base).
String getBlurredInstanceName(String service, String value, double blurLevel)
- Returns the name of the instance that results after blurring the instance defined by value. Parameters:
- String service: The service on which the blurring will be based. Currently only the value "location" is valid.
- String value: The name of the instance that will be blurred. Currently no prefixing is possible and the value mast belong to location namespace.
- double blurLevel: The level (ratio) of blurring. Mast be between 0 and 1.
String[] getServiceNameList(boolean includesubs)
Returns all the individuals of class "Service" of AstraAwarenessOntology (default namespace "astra") Parameters:
- boolean includesubs: if True then the individuals belonging in subclasses of the "Service" class will be returned. If false only direct individuals of the class "Service" will be returned.
String[] getServiceIndividualsNameList(String service,boolean includesubs)
- Returns all the individuals of service class defined by string service. Parameters:
String service: The name of the service class the individuals of which will be returned. The name may not be prefixed and the default AstraAwarenessOntology namespace (astra) will be assumed.
- boolean includesubs: if True then the individuals belonging in subclasses of the class defined by service will be returned. If false only direct individuals of the service class will be returned.
String[] getSuperLocationsForLocation(String Location)
- Returns all locations that contain the location defined by the string location. The selection is done using the astra location ontology. Parameters:
- String Location: The name of the location. It mast exist as individual in location ontology. It mast not be prefixed. The "location:" prefix is automatically added.
String[] getSubjectsByRelation(String predicate, String object[, Boolean inference[, ResultPrefixType ptype[, String defaultPrefix]]])
- Returns all entities that participate as subjects to an instance of the relation defined by predicate with object the resource defined by object (?x predicate object : Eg. if we want all the ?x where ?x rdfs:subClassOf location:Location we call getSubjectsByRelation("rdfs:subClassOf", "location:Location") ). Parameters:
- String predicate: The relation. The predicate can be prefixed in full or short form. If it is not prefixed and defaultPrefix parameter is given the predicate is prefixed with this prefix. If the predicate is not prefixed and no defaultPrefix is given the ontology default namespace prefix is assumed.
- String object: The object. The object can be prefixed in full or short form. If it is not prefixed and defaultPrefix parameter is given the object is prefixed with this prefix. If the object is not prefixed and no defaultPrefix is given the ontology default namespace prefix is assumed.
- Boolean inference: If true then inference will be used and indirect (transitive) relations will be taken into account. If false or not defined then only direct relations will be considered.
ResultPrefixType ptype [Optional]: Names Prefixing type. Controls the way the returned names are prefixed depending on the XML namespace they belong to. For available options see OntologyManager/ResultPrefixType. Default is no prefixing (OntologyManager.ResultPrefixType.PREFIX_SKIP_ALL).
- String defaultPrefix [Optional]: If ptype parameter is present, defaultPrefix declares the namespace that is considered default for this call.
The names belonging to defaultPrefix namespace will or will not be prefixed with it, depending on ptype parameter. Names belonging to other namespaces may or may not be prefixed depending on ptype parameter (see OntologyManager/ResultPrefixType). defaultPrefix may be in URI format (eg. "http://my.domain/MyOntology.owl#" - Note that URIs mast end with #), or a known short prefix name (e.g. "location") If not specified the default prefix is the default xml namespace declared into the ontology XML/OWL code (xmlns and xml:base).
String[] getObjectsByRelation(String subject, String predicate[, Boolean inference[,ResultPrefixType ptype[, String defaultPrefix]]]
- Returns all entities that participate as objects to an instance of the relation defined by predicate with subject the resource defined by subject (subject predicate ?x : Eg. if we want all the ?x where location:Location rdfs:subClassOf ?x we call getObjectsByRelation("location:Location", "rdfs:subClassOf") ). Parameters:
- String subject: The subject. The subject can be prefixed in full or short form. If it is not prefixed and defaultPrefix parameter is given the name is prefixed with this prefix. If the subject is not prefixed and no defaultPrefix is given the ontology default namespace prefix is assumed.
- String predicate: The relation. The predicate can be prefixed in full or short form. If it is not prefixed and defaultPrefix parameter is given the name is prefixed with this prefix. If the predicate is not prefixed and no defaultPrefix is given the ontology default namespace prefix is assumed.
- Boolean inference [Optional]: If true then inference will be used and indirect (transitive) relations will be taken into account. If false or not defined then only direct relations will be considered.
ResultPrefixType ptype [Optional]: Names Prefixing type. Controls the way the returned names are prefixed depending on the XML namespace they belong to. For available options see OntologyManager/ResultPrefixType. Default is no prefixing (OntologyManager.ResultPrefixType.PREFIX_SKIP_ALL).
- String defaultPrefix [Optional]: If ptype parameter is present, defaultPrefix declares the namespace that is considered default for this call.
The names belonging to defaultPrefix namespace will or will not be prefixed with it, depending on ptype parameter. Names belonging to other namespaces may or may not be prefixed depending on ptype parameter (see OntologyManager/ResultPrefixType). defaultPrefix may be in URI format (eg. "http://my.domain/MyOntology.owl#" - Note that URIs mast end with #), or a known short prefix name (e.g. "location") If not specified the default prefix is the default xml namespace declared into the ontology XML/OWL code (xmlns and xml:base).
String queryOntologyForXmlString(String query, boolean inf)
- Queries the ontology with the query given in query string and Returns the query result in xml format. Parameters:
- String query: The query in SPARQL format. All namespaces and prefixes mast be declared and all names mast be properly prefixed into the query. No prefixes processing or addition/substitution takes place.
- boolean inf: If it is true the inference model for OWL class inheritance will be used. If false, the palin model will be used and no inference will take place.
void updateOntology(String query)
- Updates the ontology model according to the update query. Parameters:
- String query: The update query. (To be further explained)
Map<String,String> getPrefixes([boolean reverse])
Returns the declared prefixes in a string to string map. If direction parameter is not set or is false, the map has the structure (URI string (key) => Short prefix name (value)). If reverse parameter is set to true then the map has the structure (Short prefix name (key) => URI string (value)). Parameters:
- bool reverse [Optional] : If set to true then the map is returned in reverse direction than default.
void addPrefix(String uri, String shortname)
Adds the pair uri => shortname at Ontology manager's private prefixes map. Parameters:
- String uri : The uri form of the prefix. This mast be a valid URI, or an exception will be thrown.
- String shortname: The short form of the prefix.
void addApplication(String id, String label, String description) throws Exception
- Adds an application defined by is id, label and description info in the ontology knowledge base. If an ontology with the same id already exists an exception is thrown. Parameters:
- String id: The application Id.
- String label: The application label.
- String description: The application description.
void setApplicationLabel(String applicationId, String label) throws Exception
- Sets the label for the application with id applicationId to label. An exception is thrown if there is no application with id applicationId in the ontology. Parameters:
- String applicationId: The id of the application.
- String label: The string to be set as label value.
void setApplicationDescription(String applicationId, String description) throws Exception
- Sets the description for the application with id applicationId to label. An exception is thrown if there is no application with id applicationId in the ontology. Parameters:
- String applicationId: The id of the application.
- String description: The string to be set as description value.
boolean applicationExists(String applicationId)
- Determines whether an application with the given applicationId exists in the ontology knowledge base. Returns true if the application exists and false if not. Parameters:
- String applicationId: The id of the application.
String getApplicationLabel(String applicationId)
- Returns the label of the application identified with applicationId. Parameters:
- String applicationId: The id of the application.
String getApplicationDescription(String applicationId)
- Returns the description of the application identified with applicationId. Parameters:
- String applicationId: The id of the application.
String getApplicationUri(String applicationId)
- Returns the URI of the application inside the ontology. This value is the unique resource identifier for the application into the ontology. It can be used for inclusion in direct queries to ontology. Parameters:
- String applicationId: The id of the application.
void addApplicationParameter(String name, String dataType, String defaultValue, String description)
- Adds an application parameter into the ontology knowledge base. Parameters:
- String name: The name of the parameter.
- String dataType: The dataType of the parameter. (This is free text for now. Internally only "String" value has some meaning for parameter validation)
- String defaultValue: The defaultValue of the parameter.
- String description: The description of the parameter.
String getParameterType(String parameterName)
- Returns a string containing the data type of parameter with name parameterName. Parameters:
- String parameterName: The name of the parameter.
String getParameterDefaultValue(String parameterName)
- Returns a string containing the default value of parameter with name parameterName. Parameters:
- String parameterName: The name of the parameter.
String getParameterDescription(String parameterName)
- Returns a string containing the description of parameter with name parameterName. Parameters:
- String parameterName: The name of the parameter.
String [] getApplicationParameters()
- Returns an array of strings that are the names of the application parameters that exist into the ontology knowledge base.
boolean applicationParameterExists(String parameterName)
- Returns true if the parameter exists in the knowledge base, false otherwise. Parameters:
- String parameterName: The name of the parameter.
void setApplicationParameterValue(String applicationId, String parameter, String value) throws Exception
- Sets the (parameter, value) pair for application with id applicationId. If the application or the parameter do not exist in the ontology, an exception is thrown. Parameters:
- String applicationId: The id of the application.
- String parameter: The name of the parameter.
- String value: The value of the parameter for this application.
void removeApplicationParameterValue(String applicationId, String parameter, String value) throws Exception
- Removes the (parameter, value) pair from the application with id applicationId. If the application or the parameter does not exist in the ontology, an exception is thrown. Parameters:
- String applicationId: The id of the application.
- String parameter: The name of the parameter.
- String value: The value of the parameter for this application.
String[] getApplicationParameterValues(String applicationId, String parameter)
- Returns an array of strings containing the values of the parameter parameter for the application applicationId. Parameters:
- String applicationId: The id of the application.
- String parameter: The name of the parameter.
Note: This method replaced the old getApplicationParameterValue that is no longer available. Please update your calls if nessesary.
boolean validateParameterValue(String applicationId, String parameter)
- Determines if the value of the parameter for the application is valid. Returns true if valid, false otherwise. (Currently validates only String parameters. For any other data type it returns false.) Parameters:
- String applicationId: The id of the application.
- String parameter: The name of the parameter.
String[][] getApplicationParametersValues(String applicationId)
- Returns a ?x2 array of strings containing the values of all parameters for application with id applicationId. The first column of each row is the name of the paramater and the second a corresponding value. Parameters:
- String applicationId: The id of the application.
boolean hasApplicationParameterValue(String applicationId, String parameter, String value)
- Returns true if the application identified by applicationId has the value value for the parameter parameter, false otherwise. Parameters:
- String applicationId: The id of the application.
- String parameter: The name of the parameter.
- String value: The value of the parameter.
String[] searchApplicationByParameters(String [][] parameters)
- Returns an array of strings that are the ids of the applications that match with the provided (parameter name, value) pairs. Parameters:
String [][] parameters: A ?x2 array of strings containing the values of parameters that will be matched. The first column of each row is the name of the paramater and the second the corresponding value. E.g. String [][] parameters = { { “Location” , “Patras”} , { “Time”, “Weekly”} , { “Category” , “Social” } ... };
String[][] searchApplicationBySimilarity(String applicationId)
- Returns a ?x2 array of strings containing the ids of matched applications and their corresponding rank (match ratio). The first column of each row is the id of the application and the second the rank converted to string from float. The rank is in (0,1). Applications with rank=0 are not returned. rank=1 means that all parameters match. Parameters:
- String applicationId: The id of the application.