Magentix2
2.1.1
|
Public Member Functions | |
SFInterface () | |
void | clean () |
void | writeModel () |
String | registerService (String serviceURL) throws MySQLException |
String | deregisterService (String serviceProfile) throws MySQLException |
String | getService (String serviceProfile) throws MySQLException |
String | searchService (ArrayList< String > inputs, ArrayList< String > outputs, ArrayList< String > keywords) throws MySQLException |
String | removeProvider (String serviceProfile, String providerName) throws MySQLException |
This class implements the Service Facilitator (SF) services.
Definition at line 55 of file SFInterface.java.
Constructor of the SFInterface
Definition at line 67 of file SFInterface.java.
{
super();
l10n = new THOMASMessages();
}
Makes a clean to the connection of Jena DB. This deletes all the information in the Jena DB.
Definition at line 125 of file SFInterface.java.
{ try { IDBConnection conn = JenaDBConnection(); conn.cleanDB(); conn.close(); } catch (Exception e) { e.printStackTrace(); } }
String es.upv.dsic.gti_ia.organization.SFInterface.deregisterService | ( | String | serviceProfile | ) | throws MySQLException |
Deregister service of the SF. It removes a complete service given its service profile URI.
serviceProfile | URI of the service to deregister |
MySQLException |
Definition at line 444 of file SFInterface.java.
{ String resultXML = "<response>\n<serviceName>DeregisterService</serviceName>\n"; IDBConnection conn; try { conn = JenaDBConnection(); } catch (DBConnectionException e1) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + e1.getContent() + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } ModelMaker maker = ModelFactory.createModelRDBMaker(conn); Model base = maker.createModel("http://example.org/ontologias"); OntModel m = ModelFactory.createOntologyModel(getModelSpec(maker), base); String serviceURI=""; try { String profileServName = getProfileServiceName(serviceProfile, null, m); if (profileServName == null || profileServName == "") { // service does not exist resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.SERVICE_PROFILE_NOT_FOUND, serviceProfile) + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } else { serviceURI = getServiceURI(serviceProfile, null, m); String serviceProcess = getServiceProcess(serviceURI, null, m); ArrayList<String> providers = getProviders(serviceProfile, null, m); Iterator<String> iterProvs = providers.iterator(); while (iterProvs.hasNext()) { String provider = iterProvs.next(); StringTokenizer tokProv = new StringTokenizer(provider, "#"); tokProv.nextToken(); String providerName = tokProv.nextToken(); removeProvider(serviceProfile, providerName, m); } removeProcess(serviceProcess, serviceProfile, m); removeProfile(serviceProfile, serviceURI, m); } } catch (ServiceURINotFoundException e){ resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.SERVICE_URI_NOT_FOUND, serviceURI) + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } catch (Exception e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.SERVICE_PROFILE_NOT_FOUND, serviceProfile) + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } finally { closeModels(maker, base, m, conn); } resultXML += "<status>Ok</status>\n"; resultXML += "<result>\n<description>Service " + serviceProfile + " Deregistered</description>\n</result>\n"; resultXML += "</response>"; return resultXML; }
String es.upv.dsic.gti_ia.organization.SFInterface.getService | ( | String | serviceProfile | ) | throws MySQLException |
Implementation of the SF service Get Service. It returns an OWL-S specification with the information of the given service.
serviceProfile | URI to extract data from |
MySQLException |
Definition at line 532 of file SFInterface.java.
{ String resultXML = "<response>\n<serviceName>GetService</serviceName>\n"; String owlsService = ""; IDBConnection conn; try { conn = JenaDBConnection(); } catch (DBConnectionException e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + e.getContent() + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } ModelMaker maker = ModelFactory.createModelRDBMaker(conn); Model base = maker.createModel("http://example.org/ontologias"); OntModel m = ModelFactory.createOntologyModel(getModelSpec(maker), base); try { owlsService = getServiceOWLS(serviceProfile, m); } catch (ServiceProfileNotFoundException e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + e.getContent() + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } finally { closeModels(maker, base, m, conn); } if (owlsService == null || owlsService == "") { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.SERVICE_PROFILE_NOT_FOUND, serviceProfile) + "</description>\n</result>\n"; } else { resultXML += "<status>Ok</status>\n"; resultXML += "<result>\n<specification><!-- \n" + owlsService + " -->\n</specification>\n</result>\n"; } resultXML += "</response>"; return resultXML; }
String es.upv.dsic.gti_ia.organization.SFInterface.registerService | ( | String | serviceURL | ) | throws MySQLException |
The RegisterService tries to register the service that is specified as parameter. If it is already registered, it registers the new providers and/or groundings.
serviceURL | is the original URL of the OWL-S specification of the service |
MySQLException |
Definition at line 216 of file SFInterface.java.
{ String resultXML = "<response>\n<serviceName>RegisterService</serviceName>\n"; String owlsService = ""; String description = ""; int nGrounds = 0, nProviders = 0; boolean fullRegister = false; IDBConnection conn; try { conn = JenaDBConnection(); } catch (DBConnectionException e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + e.getContent() + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } ModelMaker maker = ModelFactory.createModelRDBMaker(conn); Model base = maker.createModel("http://example.org/ontologias"); OntModel m = ModelFactory.createOntologyModel(getModelSpec(maker), base); try { // open the serviceURL as a file URL url = new URL(serviceURL); BufferedReader inBR = new BufferedReader(new InputStreamReader(url.openStream())); // read lines to find if it is an XML document String line = inBR.readLine(); boolean isXML = false; while (line != null) { if (!line.contains("<?xml version=")) { System.out.println(line); line = inBR.readLine(); } else { isXML = true; break; } } // is not an XML document, return error if (!isXML) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.INVALID_SERVICE_URL, serviceURL) + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } } catch (Exception e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.INVALID_SERVICE_URL, serviceURL) + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } try { String serviceName = getProfileServiceName(null, serviceURL, m); String textDescription = getProfileTextDescription(null, serviceURL, m); ArrayList<String> inputs = getInputs(null, serviceURL, m); ArrayList<String> outputs = getOutputs(null, serviceURL, m); ArrayList<String> inputsParams = getInputParameterTypes(inputs, serviceURL, m); ArrayList<String> outputParams = getOutputParameterTypes(outputs, serviceURL, m); String regServiceProfile = searchRegisteredServices(serviceName, textDescription, inputsParams, outputParams, m); if (!regServiceProfile.equalsIgnoreCase("")) { // System.out.println("Service already registered: " + // regServiceProfile); ArrayList<String> newProviders = getProviders(null, serviceURL, m); // try to register the providers if they are not registered ArrayList<String> registeredProviders = getProviders(regServiceProfile, null, m); ArrayList<String> registeredProvidersNames = new ArrayList<String>(); Iterator<String> iterRegsProvs = registeredProviders.iterator(); while (iterRegsProvs.hasNext()) { registeredProvidersNames.add(getName(iterRegsProvs.next())); } ArrayList<String> providersToAdd = new ArrayList<String>(); Iterator<String> iterNewProviders = newProviders.iterator(); while (iterNewProviders.hasNext()) { String newProv = getName(iterNewProviders.next()); if (!registeredProvidersNames.contains(newProv)) providersToAdd.add(newProv); } nProviders = providersToAdd.size(); if (!providersToAdd.isEmpty()) { String fileName = "tmp.owls"; writeProvidersOWLSFile(serviceURL, regServiceProfile, fileName, m); try { File file = new File(fileName); InputStream in = new FileInputStream(file); m.read(in, ""); m.commit(); } catch (FileNotFoundException e) { e.printStackTrace(); } } // obtain the registered wsdl docs and the one that has to be // registered. // If the new wsdl doc is different, it is registered ArrayList<String> wsdlsToRegister = getWSDLDocumentFromServiceURL(serviceURL); String serviceURI = getServiceURI(regServiceProfile, null, m); ArrayList<String> groundings = getGroundings(serviceURI, null, m); Iterator<String> iterWsdlsToRegister = wsdlsToRegister.iterator(); while (iterWsdlsToRegister.hasNext()) { String wsdlToRegister = iterWsdlsToRegister.next(); Iterator<String> iterGrounds = groundings.iterator(); String groundingURI = ""; boolean found = false; while (iterGrounds.hasNext()) { groundingURI = iterGrounds.next(); String atomicProcessGrounding = getAtomicProcessGrounding(groundingURI, null, m); String WSDLDocandDatatype = getWSDLDocument(atomicProcessGrounding, null, m); if (WSDLDocandDatatype.equalsIgnoreCase(wsdlToRegister)) { found = true; break; } } if (!found) { // System.out.println("Register new grounding"); nGrounds++; StringTokenizer token = new StringTokenizer(wsdlToRegister, "^^"); String wsdlDoc = token.nextToken(); wsdlToRegister = "\"" + wsdlDoc + "\"" + "^^xsd:anyURI"; String fileName = "tmp.owls"; writeGroundingOWLSFile(serviceURL, regServiceProfile, wsdlToRegister, fileName, m); try { File file = new File(fileName); InputStream in = new FileInputStream(file); m.read(in, ""); m.commit(); } catch (FileNotFoundException e) { e.printStackTrace(); } } } if (nGrounds == 0 && nProviders == 0) description = l10n.getMessage(MessageID.ALREADY_REGISTERED, regServiceProfile); else description = nGrounds + " groundings and " + nProviders + " providers registered to service profile: " + regServiceProfile; // System.out.println(nGrounds + " groundings and " + nProviders // + " providers registered to service profile: " + // regServiceProfile); } else { // load the service profile in the database m.read(serviceURL); m.commit(); regServiceProfile = getProfileURIfromURL(serviceURL); description = "Service registered: " + regServiceProfile; // System.out.println("Service registered: " + // regServiceProfile); fullRegister = true; } owlsService = getServiceOWLS(regServiceProfile, m); } catch (Exception e) { e.printStackTrace(); String msg; if (e instanceof THOMASException) msg = ((THOMASException) e).getContent(); else msg = l10n.getMessage(MessageID.INVALID_SERVICE_URL, serviceURL); resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + msg + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } finally { closeModels(maker, base, m, conn); } if (nGrounds == 0 && nProviders == 0 && !fullRegister) resultXML += "<status>Error</status>\n"; else resultXML += "<status>Ok</status>\n"; resultXML += "<result>\n<description>" + description + "</description>\n" + "<specification>\n<!-- " + owlsService + " -->\n</specification>\n</result>\n"; resultXML += "</response>"; return resultXML; }
String es.upv.dsic.gti_ia.organization.SFInterface.removeProvider | ( | String | serviceProfile, |
String | providerName | ||
) | throws MySQLException |
Removes a provider from a registered service in the Jena DB
serviceProfile | URI of the service to remove the provider |
providerName | of the provider to remove, or the complete grounding URI |
MySQLException |
Definition at line 971 of file SFInterface.java.
{ String resultXML = "<response>\n<serviceName>RemoveProvider</serviceName>\n"; IDBConnection conn; try { conn = JenaDBConnection(); } catch (DBConnectionException e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + e.getContent() + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } ModelMaker maker = ModelFactory.createModelRDBMaker(conn); Model base = maker.createModel("http://example.org/ontologias"); OntModel m = ModelFactory.createOntologyModel(getModelSpec(maker), base); try { removeProvider(serviceProfile, providerName, m); } catch (ServiceProfileNotFoundException e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + e.getContent() + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } finally { closeModels(maker, base, m, conn); } resultXML += "<status>Ok</status>\n"; resultXML += "<result>\n<description>" + "Provider or grounding " + providerName + " removed" + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; }
String es.upv.dsic.gti_ia.organization.SFInterface.searchService | ( | ArrayList< String > | inputs, |
ArrayList< String > | outputs, | ||
ArrayList< String > | keywords | ||
) | throws MySQLException |
The SearchService receives as parameters three lists with the data types of the inputs and outputs desired, and another with the keywords desired. With these parameters, the service searches in the Jena DB and returns the more similar services, that is, the services that have the same (or almost the same) data types as inputs and outputs, weighted in function of the amount of similarity.
inputs | list of the desired input parameter type to search a similar service. Example: "http://127.0.0.1/ontology/books.owl#Novel"^^xsd:anyURI |
outputs | list of the desired output parameter type to search a similar service. Example: "http://127.0.0.1/ontology/books.owl#Novel"^^xsd:anyURI |
keywords | list of the desired keywords that describes a service |
MySQLException |
Definition at line 602 of file SFInterface.java.
{ String resultXML = "<response>\n<serviceName>SearchService</serviceName>\n"; String itemsList = ""; // store a list of profiles with their similarity weights to the service ArrayList<Profile> profiles = new ArrayList<Profile>(); IDBConnection conn; try { conn = JenaDBConnection(); } catch (DBConnectionException e) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + e.getContent() + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } ModelMaker maker = ModelFactory.createModelRDBMaker(conn); Model base = maker.createModel("http://example.org/ontologias"); OntModel m = ModelFactory.createOntologyModel(getModelSpec(maker), base); try { ArrayList<String> candidatesInputs = new ArrayList<String>(); if (inputs != null && !inputs.isEmpty()) { // the service searches each input and add to a list each // service that has an equal input as a candidate Iterator<String> iterInputs = inputs.iterator(); while (iterInputs.hasNext()) { String in = iterInputs.next(); String queryStr = "prefix xsd: <http://www.w3.org/2001/XMLSchema#>" + "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { ?x a process:Input ; process:parameterType " + in + " . }"; Query query = QueryFactory.create(queryStr); // Execute the query and obtain results QueryExecution querySearchInputs = QueryExecutionFactory.create(query, m); ResultSet resultsSearchInputs = querySearchInputs.execSelect(); if (resultsSearchInputs != null) { while (resultsSearchInputs.hasNext()) { QuerySolution sol = resultsSearchInputs.next(); Resource resource = sol.getResource("x"); String cand = resource.getURI(); if (!candidatesInputs.contains(cand)) candidatesInputs.add(cand); }// end for }// end if // close the query querySearchInputs.close(); } // obtain the profileURL of each candidate and create their // profiles Iterator<String> iterCandidates = candidatesInputs.iterator(); while (iterCandidates.hasNext()) { String cand = iterCandidates.next(); String queryStr = "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { ?x profile:hasInput " + "<" + cand + ">" + " }"; Query query = QueryFactory.create(queryStr); // Execute the query and obtain results QueryExecution querySearchInputs = QueryExecutionFactory.create(query, m); ResultSet resultsSearchInputs = querySearchInputs.execSelect(); if (resultsSearchInputs != null && resultsSearchInputs.hasNext()) { QuerySolution sol = resultsSearchInputs.next(); Resource resource = sol.getResource("x"); String profileURL = resource.getURI(); Profile profile = new Profile(profileURL, 0f); if (!profiles.contains(profile)) profiles.add(profile); } } } ArrayList<String> candidatesOutputs = new ArrayList<String>(); if (outputs != null && !outputs.isEmpty()) { // the service searches each output and add to a list each // service that has an equal output as a candidate Iterator<String> iterOutputs = outputs.iterator(); while (iterOutputs.hasNext()) { String in = iterOutputs.next(); String queryStr = "prefix xsd: <http://www.w3.org/2001/XMLSchema#>" + "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { ?x a process:Output ; process:parameterType " + in + " . }"; Query query = QueryFactory.create(queryStr); // Execute the query and obtain results QueryExecution querySearchInputs = QueryExecutionFactory.create(query, m); ResultSet resultsSearchInputs = querySearchInputs.execSelect(); if (resultsSearchInputs != null) { while (resultsSearchInputs.hasNext()) { QuerySolution sol = resultsSearchInputs.next(); Resource resource = sol.getResource("x"); String cand = resource.getURI(); if (!candidatesOutputs.contains(cand)) candidatesOutputs.add(cand); }// end for }// end if // close the query querySearchInputs.close(); } // obtain the profileURL of each candidate and create their // profiles Iterator<String> iterCandidates = candidatesOutputs.iterator(); while (iterCandidates.hasNext()) { String cand = iterCandidates.next(); String queryStr = "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { ?x profile:hasOutput " + "<" + cand + ">" + " }"; Query query = QueryFactory.create(queryStr); // Execute the query and obtain results QueryExecution querySearchInputs = QueryExecutionFactory.create(query, m); ResultSet resultsSearchInputs = querySearchInputs.execSelect(); if (resultsSearchInputs != null && resultsSearchInputs.hasNext()) { QuerySolution sol = resultsSearchInputs.next(); Resource resource = sol.getResource("x"); String profileURL = resource.getURI(); Profile profile = new Profile(profileURL, 0f); if (!profiles.contains(profile)) profiles.add(profile); } } } if (keywords != null && !keywords.isEmpty()) { HashMap<String, String> textDescriptions = getProfilesTextDescriptions(m); Iterator<String> iterTextDescriptions = textDescriptions.keySet().iterator(); while (iterTextDescriptions.hasNext()) { String profileURI = iterTextDescriptions.next(); String textDescription = textDescriptions.get(profileURI).toLowerCase().trim(); Iterator<String> iterKeywords = keywords.iterator(); while (iterKeywords.hasNext()) { String keyword = iterKeywords.next().toLowerCase().trim(); if (textDescription.contains(keyword)) { Profile profile = new Profile(profileURI, 0f); if (!profiles.contains(profile)) profiles.add(profile); } } } } Iterator<Profile> iterProfiles = profiles.iterator(); while (iterProfiles.hasNext()) { Profile profile = iterProfiles.next(); int inputsProfile = 0; int outputsProfile = 0; int sameInputs = 0; int sameOutputs = 0; // SEARCH INPUTS String queryStr = "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { " + "<" + profile.getUrl() + ">" + " profile:hasInput ?x }"; Query query = QueryFactory.create(queryStr); // Execute the query and obtain results QueryExecution querySearchInputs = QueryExecutionFactory.create(query, m); ResultSet resultsSearchInputs = querySearchInputs.execSelect(); if (resultsSearchInputs != null) { while (resultsSearchInputs.hasNext()) { inputsProfile++; QuerySolution sol = resultsSearchInputs.next(); if (inputs != null && !inputs.isEmpty() && sameInputs < inputs.size()) { Resource resource = sol.getResource("x"); String input = resource.getURI(); // explore all inputs (searching their type) to find // out if it is in the service String queryStrType = "prefix xsd: <http://www.w3.org/2001/XMLSchema#>" + "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { <" + input + "> a process:Input ; process:parameterType ?x . }"; Query queryType = QueryFactory.create(queryStrType); // Execute the query and obtain results QueryExecution querySearchInputType = QueryExecutionFactory.create(queryType, m); ResultSet resultsSearchInputType = querySearchInputType.execSelect(); if (resultsSearchInputType != null && resultsSearchInputType.hasNext()) { QuerySolution sol2 = resultsSearchInputType.next(); Literal literal2 = sol2.getLiteral("x"); String parameterType = literal2.getString(); Iterator<String> iterInputsSearch = inputs.iterator(); while (iterInputsSearch.hasNext()) { String inputSearch = iterInputsSearch.next(); String inputSearchModif = inputSearch.replaceAll("\"", ""); StringTokenizer stringTokenizer = new StringTokenizer(inputSearchModif, "^^"); inputSearchModif = stringTokenizer.nextToken(); if (inputSearchModif.equalsIgnoreCase(parameterType)) { sameInputs++; break; } } } } } } // SEARCH OUTPUTS String queryStrOutputs = "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { " + "<" + profile.getUrl() + ">" + " profile:hasOutput ?x }"; Query queryOutputs = QueryFactory.create(queryStrOutputs); // Execute the query and obtain results QueryExecution querySearchOutputs = QueryExecutionFactory.create(queryOutputs, m); ResultSet resultsSearchOutputs = querySearchOutputs.execSelect(); if (resultsSearchOutputs != null) { while (resultsSearchOutputs.hasNext()) { outputsProfile++; QuerySolution sol = resultsSearchOutputs.next(); if (outputs != null && !outputs.isEmpty() && sameOutputs < outputs.size()) { Resource resource = sol.getResource("x"); String output = resource.getURI(); // explore all outputs (searching their type) to // find out if it is in the service String queryStrType = "prefix xsd: <http://www.w3.org/2001/XMLSchema#>" + "prefix profile: <http://www.daml.org/services/owl-s/1.1/Profile.owl#>" + "prefix process: <http://www.daml.org/services/owl-s/1.1/Process.owl#>" + "select ?x where { <" + output + "> a process:Output ; process:parameterType ?x . }"; Query queryType = QueryFactory.create(queryStrType); // Execute the query and obtain results QueryExecution querySearchOutputType = QueryExecutionFactory.create(queryType, m); ResultSet resultsSearchOutputType = querySearchOutputType.execSelect(); if (resultsSearchOutputType != null && resultsSearchOutputType.hasNext()) { QuerySolution sol2 = resultsSearchOutputType.next(); Literal literal2 = sol2.getLiteral("x"); String parameterType = literal2.getString(); Iterator<String> iterOutputsSearch = outputs.iterator(); while (iterOutputsSearch.hasNext()) { String outputSearch = iterOutputsSearch.next(); String outputSearchModif = outputSearch.replaceAll("\"", ""); StringTokenizer stringTokenizer = new StringTokenizer(outputSearchModif, "^^"); outputSearchModif = stringTokenizer.nextToken(); if (outputSearchModif.equalsIgnoreCase(parameterType)) { sameOutputs++; break; } } } } } } int keywordsFound = 0; if (keywords != null && !keywords.isEmpty()) { // obtain the similarity of the searched keywords in the // profile text description String textDescription = getProfileTextDescription(profile.getUrl(), null, m).toLowerCase().trim(); Iterator<String> iterKeywords = keywords.iterator(); while (iterKeywords.hasNext()) { String keyword = iterKeywords.next().toLowerCase().trim(); if (textDescription.contains(keyword)) keywordsFound++; } } // obtain the final similarity degree of the profile float inputsSimilarity = 0, outputsSimilarity = 0, similarityToKeywords = 0, similaritiesUsed = 0; if (inputs != null && !inputs.isEmpty()) { inputsSimilarity = ((float) sameInputs / inputsProfile) * ((float) sameInputs / inputs.size()); similaritiesUsed++; } if (outputs != null && !outputs.isEmpty()) { outputsSimilarity = ((float) sameOutputs / outputsProfile) * ((float) sameOutputs / outputs.size()); similaritiesUsed++; } if (keywords != null && !keywords.isEmpty()) { similarityToKeywords = (float) keywordsFound / keywords.size(); similaritiesUsed++; } float similarity = (1.0f / similaritiesUsed) * inputsSimilarity + (1.0f / similaritiesUsed) * outputsSimilarity + (1.0f / similaritiesUsed) * similarityToKeywords; profile.setSuitability(similarity); }// end iterator profiles // sort the found candidate profiles by their similarity Collections.sort(profiles); iterProfiles = profiles.iterator(); while (iterProfiles.hasNext()) { Profile profile = iterProfiles.next(); itemsList += "\t<item>\n\t\t<profile>" + profile.getUrl() + "</profile>\n\t\t<quantity>" + profile.getSuitability() + "</quantity>\n\t</item>\n"; } } catch (Exception e) { e.printStackTrace(); resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.INVALID_DATA_TYPE) + "</description>\n</result>\n"; resultXML += "</response>"; return resultXML; } finally { closeModels(maker, base, m, conn); } if (profiles.size() == 0) { resultXML += "<status>Error</status>\n"; resultXML += "<result>\n<description>" + l10n.getMessage(MessageID.SERVICES_NOT_FOUND) + "</description>\n</result>\n"; } else { resultXML += "<status>Ok</status>\n"; resultXML += "<result>\n" + itemsList + "</result>\n"; } resultXML += "</response>"; return resultXML; }
Writes to the standard output the Jena DB Model
Definition at line 158 of file SFInterface.java.
{ try { IDBConnection conn = JenaDBConnection(); ModelMaker maker = ModelFactory.createModelRDBMaker(conn); Model base = maker.createModel("http://example.org/ontologias"); OntModel m = ModelFactory.createOntologyModel(getModelSpec(maker), base); m.write(System.out, "N3"); closeModels(maker, base, m, conn); conn.close(); } catch (Exception e) { e.printStackTrace(); } }