Package fi.tut.mei.capabilityQueryLib
Class Client
- java.lang.Object
-
- fi.tut.mei.capabilityQueryLib.Client
-
public class Client extends Object
Client is the main class when using cql programmatically. A Client instance is created from either just from the model ontology or from a resource instances ontology that contains actual resources. It can be used to get information like capabilities and resources from the ontology. It can calculate combined capabilities and their parameters for device combinations in the ontology. It can also generate combination possibilities for given capabilities by creating different combinations from the resources available in the ontology.- Author:
- hylli
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Client.CombinedCapabilityInfo
The result of a combined capability query.static class
Client.TemplateAlreadyExistsException
Exception that can be thrown if trying to add a query template with a name that already has been added.
-
Field Summary
Fields Modifier and Type Field Description static String
BLUEPRINT_ONTCLASS
static String
CAPABILITY_NS
the capability ontology name space urlstatic String
CAPABILITY_ONTCLASS
The URI of the capability ontology classstatic String
COMMON_CONCEPTS_NS
common concepts ontology name spacestatic String
DEFAULT_RESOURCE_ONTOLOGY_LOCATION
Default location for the resource instance ontology.static String
DEVICE_COMBINATION_ONTCLASS
static String
INDIVIDUAL_DEVICE_ONTCLASS
static String
PROCESS_TAXONOMY_NS
The process taxonomy model ontology name space.static String
RDID_PROPERTY
static String
RDURL_PROPERTY
static String
REAL_DEVICE_COMBINATION_CLASS_URI
static String
RESOURCE_NS
the resource ontology name space urlstatic String
TEST_DEVICE_COMBINATION_CLASS_URI
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addResources(InputStream input)
Add new resource instances to clients existing ones.void
addResources(org.apache.jena.rdf.model.Model resources)
Add new resource instances to clients existing ones.void
addTemplate(String name, String template)
Add a query template that can be used with loadTemplateorg.apache.jena.ontology.OntModel
createOntologyModel(InputStream content)
Create memory based OWL model that uses client's own document manager not the global one.org.apache.jena.query.ResultSet
executeQuery(String file)
Execute the SPARQL query in the given file for the ontology.ParameterObject
getBasicResourceInformation()
Get basic resource information.Blueprint
getBlueprint(String name)
Get information about the given blueprint.List<String>
getBlueprints()
Get the names of all of the device blueprints in the ontology.List<String>
getBlueprintsByCapability(Capability capability)
List names of blueprints that have the given capability.List<Capability>
getCapabilities()
Get all capabilities in the ontology.Capability
getCapability(String name)
get a capability by nameCapabilityAssociation
getCapabilityAssociation(String name)
Deprecated.always returns null since capability associations no longer have names.List<CapabilityAssociation>
getCapabilityAssociations()
Deprecated.Returns always an empty list since associations are no longer listed.org.apache.jena.ontology.OntModel
getCombinationPossibilitiesForCapability(Capability capability)
Find all device combination possibilities that have the given combined capability and can be formed from the device blueprints in the ontology.org.apache.jena.ontology.OntModel
getCombinationPossibilitiesForCapability(List<Capability> capabilities, String fileName, Predicate<List<String>> filter)
Find all device combination possibilities that have the given combined capability and can be formed from the device blueprints in the ontology.List<Client.CombinedCapabilityInfo>
getCombinedCapabilities(Collection<Capability> simpleCapabilities)
Gives combined capabilities that can be formed from some of the given capabilities.String
getDefaultNameSpace()
Get the default name space of the ontology i.e.DeviceCombination
getDeviceCombination(String name)
Get information about a device combination.List<String>
getDeviceCombinations()
Get names of all device combinations in the ontology.List<String>
getDeviceCombinationsByCapability(Capability capability)
Get names of device combinations that have a given capability.List<String>
getDevicesForBlueprint(String name)
Get list of names of individual devices that are based on the given blueprint.List<String>
getHighestLevelDeviceCombinations()
Get the names of all highest level device combinations.IndividualDevice
getIndividualDevice(String name)
Get information about the individual device with the given name.List<String>
getIndividualDevices()
Get the names of all individual devices in the ontology.List<String>
getIndividualDevicesByCapability(Capability capability)
Get list of names of individual devices that have the given capability.org.apache.jena.ontology.OntModel
getOntology()
Returns the Jena ontology model used by the client.String
getOntologyFile()
Get the file path / URI used in creating this client.String
getOntologyURI()
Get the URI of the ontology resource defined in the loaded ontology file.Parameter
getParameter(String name)
Get capability parameter with the given name.ParameterObject
getParameterObject(String name)
Get the parameter object with the given name.ProcessTaxonomyModel
getProcessTaxonomyModel()
Get an object that holds information about the process taxonomy model.Set<Capability>
getSimpleCapabilitiesForDeviceCombination(String device)
get all of the simple capabilities of a device combinationboolean
individualOfClass(String individualURI, String classURI)
Checks if the ontology has the given individual that belongs to the given class.boolean
isAllCombinedCapabilityInfo()
Get if getting of some information should be omitted when getting information about devices or device combinations.org.apache.jena.query.QueryExecution
loadTemplate(String name, Map<String,Object> params, boolean usePellet)
gets a query execution that is based on a sparql query in a file.org.apache.jena.query.QueryExecution
loadTemplate(String name, Map<String,Object> params, Map<String,Object> litParams, boolean usePellet)
gets a query execution that is based on a sparql query in a file.org.apache.jena.ontology.OntModel
saveAllDeviceCombinations(String file, org.apache.jena.ontology.OntModel onto)
Calculate combined capabilities and capability parameters for device combinations whose capabilities have not yet been calculated and save them into an ontology file.void
saveCombinedCapabilities(DeviceCombination device, String file)
Save device's combined capabilities and their calculated parameters to the given ontology file.void
saveOntology(OutputStream output)
Writes the client's ontology to the given stream.List<Capability>
searchCapability(String searchTerm, fi.tut.mei.resdescapi.util.Util.EnumSearchType type)
Search capability by name.void
setOntology(org.apache.jena.ontology.OntModel onto)
void
setResourceOntology(InputStream input)
Set the resource instance ontology of the client.void
setResourceOntology(String fileName)
Set the resource instance ontology of the client.List<String>
viewParameters(String capabilityName)
List all parameters of a capability as list of strings.
-
-
-
Field Detail
-
RESOURCE_NS
public static final String RESOURCE_NS
the resource ontology name space url- See Also:
- Constant Field Values
-
CAPABILITY_NS
public static final String CAPABILITY_NS
the capability ontology name space url- See Also:
- Constant Field Values
-
PROCESS_TAXONOMY_NS
public static final String PROCESS_TAXONOMY_NS
The process taxonomy model ontology name space.- See Also:
- Constant Field Values
-
COMMON_CONCEPTS_NS
public static final String COMMON_CONCEPTS_NS
common concepts ontology name space- See Also:
- Constant Field Values
-
DEFAULT_RESOURCE_ONTOLOGY_LOCATION
public static final String DEFAULT_RESOURCE_ONTOLOGY_LOCATION
Default location for the resource instance ontology. Used with the default constructor.- See Also:
- Constant Field Values
-
BLUEPRINT_ONTCLASS
public static final String BLUEPRINT_ONTCLASS
- See Also:
- Constant Field Values
-
INDIVIDUAL_DEVICE_ONTCLASS
public static final String INDIVIDUAL_DEVICE_ONTCLASS
- See Also:
- Constant Field Values
-
DEVICE_COMBINATION_ONTCLASS
public static final String DEVICE_COMBINATION_ONTCLASS
- See Also:
- Constant Field Values
-
TEST_DEVICE_COMBINATION_CLASS_URI
public static final String TEST_DEVICE_COMBINATION_CLASS_URI
- See Also:
- Constant Field Values
-
REAL_DEVICE_COMBINATION_CLASS_URI
public static final String REAL_DEVICE_COMBINATION_CLASS_URI
- See Also:
- Constant Field Values
-
CAPABILITY_ONTCLASS
public static final String CAPABILITY_ONTCLASS
The URI of the capability ontology class- See Also:
- Constant Field Values
-
RDID_PROPERTY
public static final String RDID_PROPERTY
- See Also:
- Constant Field Values
-
RDURL_PROPERTY
public static final String RDURL_PROPERTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Client
public Client()
Create a ontology client using the default ontology defined in RESOURCE_ONTOLOGY_LOCATION
-
Client
public Client(String fileName)
creates a ontology client that reads the ontology from the given source- Parameters:
fileName
- name of the file containing the ontology. a local file or an url
-
-
Method Detail
-
setResourceOntology
public void setResourceOntology(String fileName)
Set the resource instance ontology of the client. This assumes that the new ontology uses the same resource, capability and process taxonomy models that were processed when the client was built.- Parameters:
fileName
- the ontology file or url
-
setOntology
public void setOntology(org.apache.jena.ontology.OntModel onto)
-
createOntologyModel
public org.apache.jena.ontology.OntModel createOntologyModel(InputStream content)
Create memory based OWL model that uses client's own document manager not the global one.- Parameters:
content
- If not null the content is read to the model.- Returns:
- Ontology model with Client's document manager with the content if present.
-
setResourceOntology
public void setResourceOntology(InputStream input)
Set the resource instance ontology of the client. This assumes that the new ontology uses the same resource, capability and process taxonomy models that were processed when the client was built.- Parameters:
input
- InputStream containing the new resource instance ontology in the XML/RDF format
-
addResources
public void addResources(InputStream input)
Add new resource instances to clients existing ones. These new instances have to use the same resource, capability, taxonomy and common concepts models.- Parameters:
input
- InputStream containing a resource instances ontology in the xml/rdf format.
-
addResources
public void addResources(org.apache.jena.rdf.model.Model resources)
Add new resource instances to clients existing ones. These new instances have to use the same resource, capability, taxonomy and common concepts models.- Parameters:
resources
- a jena model containing a resource instance ontology
-
saveOntology
public void saveOntology(OutputStream output)
Writes the client's ontology to the given stream.- Parameters:
output
- stream where the client is written to
-
getParameter
public Parameter getParameter(String name)
Get capability parameter with the given name.- Parameters:
name
- parameter name- Returns:
- parameter with the name. null if no parameter with the name
-
getParameterObject
public ParameterObject getParameterObject(String name)
Get the parameter object with the given name.- Parameters:
name
- name of a parameter object- Returns:
- parameter object with the name. null if not found
-
viewParameters
public List<String> viewParameters(String capabilityName)
List all parameters of a capability as list of strings. Strings represent the parameters as a hierarchy separated by / for example payload or hasRotationMovementRanges/RotationalMovementRange/rotation_z- Parameters:
capabilityName
- name of a capability- Returns:
- a string for each parameter and parameter of each ParameterObject, Null if there is no capability with the given name.
-
getOntologyFile
public String getOntologyFile()
Get the file path / URI used in creating this client. This is either the argument given to the constructor or if the default constructor was used the DEFAULT_RESOURCE_ONTOLOGY_LOCATION- Returns:
- the ontology file used to create this client.
-
getProcessTaxonomyModel
public ProcessTaxonomyModel getProcessTaxonomyModel()
Get an object that holds information about the process taxonomy model.- Returns:
- the process taxonomy model.
-
getDeviceCombination
public DeviceCombination getDeviceCombination(String name)
Get information about a device combination. The information includes all devices, capabilities and combined capabilities for each device. Parameters with their values are also provided for individual devices and blueprints. Capability parameters are also provided for device combinations if the source ontology file contains them i.e. it was created with thesaveAllDeviceCombinations(String, OntModel)
method- Parameters:
name
- the name of a device combination- Returns:
- a device combination. null if no device combination with the given name
-
isAllCombinedCapabilityInfo
public boolean isAllCombinedCapabilityInfo()
Get if getting of some information should be omitted when getting information about devices or device combinations. This is used when generating combination possibilities or calculating combined capabilities for all combinations. In these cases not all information normally fetched is used- Returns:
- the allCombinedCapabilityInfo
-
saveCombinedCapabilities
public void saveCombinedCapabilities(DeviceCombination device, String file) throws FileNotFoundException
Save device's combined capabilities and their calculated parameters to the given ontology file. This will include also combined capabilities of the parts.- Parameters:
device
- A device combinationfile
- Path to the ontology file where the info will be saved. Can be an existing file or if not a new file will be created.- Throws:
FileNotFoundException
- file not found
-
saveAllDeviceCombinations
public org.apache.jena.ontology.OntModel saveAllDeviceCombinations(String file, org.apache.jena.ontology.OntModel onto) throws FileNotFoundException
Calculate combined capabilities and capability parameters for device combinations whose capabilities have not yet been calculated and save them into an ontology file.- Parameters:
file
- Name of the file where the information is to be saved. If null information will be not saved into a file.onto
- Ontology model where the information will be added. Can be null in which case a model is created for the information.- Throws:
FileNotFoundException
- file not found
-
getSimpleCapabilitiesForDeviceCombination
public Set<Capability> getSimpleCapabilitiesForDeviceCombination(String device)
get all of the simple capabilities of a device combination- Parameters:
device
- the device name- Returns:
- the capabilities
-
getCapability
public Capability getCapability(String name)
get a capability by name- Parameters:
name
- capability name- Returns:
- the capability. Null if there is no such capability.
-
getCapabilityAssociation
@Deprecated public CapabilityAssociation getCapabilityAssociation(String name)
Deprecated.always returns null since capability associations no longer have names.Get a capability association by name- Parameters:
name
- the capability association name- Returns:
- the capability association, null if not found
-
getCapabilityAssociations
@Deprecated public List<CapabilityAssociation> getCapabilityAssociations()
Deprecated.Returns always an empty list since associations are no longer listed.List all capability associations in the model.- Returns:
- all capability associations
-
getCapabilities
public List<Capability> getCapabilities()
Get all capabilities in the ontology.- Returns:
- List of capabilities.
-
searchCapability
public List<Capability> searchCapability(String searchTerm, fi.tut.mei.resdescapi.util.Util.EnumSearchType type)
Search capability by name.- Parameters:
searchTerm
- the search termtype
- how to search: capability name starts with, ends with, contains or exactly matches the search term.- Returns:
- List of capabilities that match the search term.
-
getCombinedCapabilities
public List<Client.CombinedCapabilityInfo> getCombinedCapabilities(Collection<Capability> simpleCapabilities)
Gives combined capabilities that can be formed from some of the given capabilities.- Parameters:
simpleCapabilities
- capabilities whose combinations are queried- Returns:
- For each combined capability an object that has the combined capability and those capabilities from the given list that produced it.
-
getBasicResourceInformation
public ParameterObject getBasicResourceInformation()
Get basic resource information.- Returns:
- ParameterObject that represents basic information that can be associated with a device such as mass.
-
getBlueprints
public List<String> getBlueprints()
Get the names of all of the device blueprints in the ontology.- Returns:
- List of blueprint names sorted alphabetically.
-
getIndividualDevices
public List<String> getIndividualDevices()
Get the names of all individual devices in the ontology.- Returns:
- List of individual device names.
-
getBlueprintsByCapability
public List<String> getBlueprintsByCapability(Capability capability)
List names of blueprints that have the given capability.- Parameters:
capability
- A capability.- Returns:
- List of blueprint names sorted alphabetically. Null if an internal error happens.
-
getCombinationPossibilitiesForCapability
public org.apache.jena.ontology.OntModel getCombinationPossibilitiesForCapability(List<Capability> capabilities, String fileName, Predicate<List<String>> filter)
Find all device combination possibilities that have the given combined capability and can be formed from the device blueprints in the ontology. The combined capabilities and capability parameters of the possibilities will be saved to the returned ontology model which will be saved to the file with the given name.- Parameters:
capabilities
- Combined capabilities that combinations are created for.fileName
- Name of the file where the possibilities ontology will be saved. If null ontology will not be saved to a file.filter
- Allows additional filtering of the created device combinations A filtering function that takes a list of URIs of devices that can be used to form a combination for the capability and returns true if they should form a device combination or false if not. If null no filtering is performed.- Returns:
- Ontology model containing the created combination possibilities and combined capabilities with parameters.
-
getCombinationPossibilitiesForCapability
public org.apache.jena.ontology.OntModel getCombinationPossibilitiesForCapability(Capability capability)
Find all device combination possibilities that have the given combined capability and can be formed from the device blueprints in the ontology. The combined capabilities and capability parameters of the possibilities will be saved to the returned ontology model.- Parameters:
capability
- Combined capability that combinations are created for.- Returns:
- Ontology model containing the created combination possibilities and combined capabilities with parameters.
-
getDeviceCombinationsByCapability
public List<String> getDeviceCombinationsByCapability(Capability capability)
Get names of device combinations that have a given capability. Note this requires that the source ontology contains combined capabilities for device combinations. The methodsaveAllDeviceCombinations(String, OntModel)
can be used to create such an ontology file.- Parameters:
capability
- the capability- Returns:
- List of device combination names. Null if there is an error.
-
getIndividualDevicesByCapability
public List<String> getIndividualDevicesByCapability(Capability capability)
Get list of names of individual devices that have the given capability.- Parameters:
capability
- capability- Returns:
- List of device names. Null in case of an internal error.
-
getBlueprint
public Blueprint getBlueprint(String name)
Get information about the given blueprint. The information includes capabilities and their parameters.- Parameters:
name
- Name of a blueprint.- Returns:
- The blueprint or null if not found or an error was encountered.
-
getIndividualDevice
public IndividualDevice getIndividualDevice(String name)
Get information about the individual device with the given name.- Parameters:
name
- the device name- Returns:
- The individual device or null if not found or an error occurs.
-
getDevicesForBlueprint
public List<String> getDevicesForBlueprint(String name)
Get list of names of individual devices that are based on the given blueprint.- Parameters:
name
- The name of a blueprint.- Returns:
- List of device names. Null if no blueprint with given name or an internal error.
-
getDeviceCombinations
public List<String> getDeviceCombinations()
Get names of all device combinations in the ontology.- Returns:
- list of device combination names
-
getHighestLevelDeviceCombinations
public List<String> getHighestLevelDeviceCombinations()
Get the names of all highest level device combinations. These device combinations are not a part of any other device combination.- Returns:
- List of device combination names or null in case of an error.
-
individualOfClass
public boolean individualOfClass(String individualURI, String classURI)
Checks if the ontology has the given individual that belongs to the given class.- Parameters:
individualURI
- the URI of the individualclassURI
- the URI of the ontology class- Returns:
- True if the individual and class exist and the individual belongs to the class. False otherwise.
-
executeQuery
public org.apache.jena.query.ResultSet executeQuery(String file) throws IOException, org.apache.jena.query.QueryParseException
Execute the SPARQL query in the given file for the ontology.- Parameters:
file
- The path to the file containing a SPARQL query- Returns:
- The query results.
- Throws:
IOException
- If there is a problem in opening the file.org.apache.jena.query.QueryParseException
- If the SPARQL query is invalid.
-
addTemplate
public void addTemplate(String name, String template) throws Client.TemplateAlreadyExistsException
Add a query template that can be used with loadTemplate- Parameters:
name
- name of the template that is used when loading templatetemplate
- the template- Throws:
Client.TemplateAlreadyExistsException
- there already is a template with the name
-
loadTemplate
public org.apache.jena.query.QueryExecution loadTemplate(String name, Map<String,Object> params, boolean usePellet) throws IOException
gets a query execution that is based on a sparql query in a file.- Parameters:
name
- the name of the query templateparams
- IRI parameters used to replace variables in the template with actual values. Represents resources in the ontology.usePellet
- true use pellet to execute query, false use Jena (no reasoning in query)- Returns:
- query execution ready for execution
- Throws:
IOException
- if template file is not found
-
loadTemplate
public org.apache.jena.query.QueryExecution loadTemplate(String name, Map<String,Object> params, Map<String,Object> litParams, boolean usePellet) throws IOException
gets a query execution that is based on a sparql query in a file.- Parameters:
name
- the name of the query template fileparams
- IRI parameters used to replace variables in the template with actual values. Represents resources in the ontology.litParams
- parameters that are literals e.g. strings, numbersusePellet
- true use pellet to execute query, false use Jena (no reasoning in query)- Returns:
- query execution ready for execution
- Throws:
IOException
- if template file is not found
-
getOntology
public org.apache.jena.ontology.OntModel getOntology()
Returns the Jena ontology model used by the client. Can be used when the user wants to work directly with the ontology for example when the client doesn't offer information required by the user.- Returns:
- the ontology
-
getDefaultNameSpace
public String getDefaultNameSpace()
Get the default name space of the ontology i.e. the one with an empty prefix- Returns:
- The default name space URI
-
getOntologyURI
public String getOntologyURI()
Get the URI of the ontology resource defined in the loaded ontology file.- Returns:
- The URI of the ontology resource. Null if not found e.g. there is no ontology resource defined in the ontology.
-
-