package uk.ac.open.kmi.watson.clientapi.test; import java.rmi.RemoteException; import uk.ac.open.kmi.watson.clientapi.OntologySearch; import uk.ac.open.kmi.watson.clientapi.OntologySearchServiceLocator; import uk.ac.open.kmi.watson.clientapi.WatsonService; public class TestOntologySearch { private OntologySearch os; public TestOntologySearch(){ OntologySearchServiceLocator locator = new OntologySearchServiceLocator(); try{ os = locator.getUrnOntologySearch(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getCause()); } } public static void main(String[] args){ TestOntologySearch app = new TestOntologySearch(); try { app.search(); app.rsearch(); app.rsearchp(); app.bestCoverage(); app.DLExpr(); app.size(); app.languages(); app.locations(); app.cacheLocation(); app.listClasses(); app.listProperties(); app.listIndividuals(); app.nbReviews(); app.avgReviews(); app.revyuURI(); app.sparql(); app.imports(); app.imported(); app.labels(); app.comments(); app.nbstats(); // app.listSC(); // can be long... } catch (RemoteException e) { e.printStackTrace(); } } public void search() throws RemoteException{ System.out.println("***** Searching Cat and Dog *****"); String[] params = {"cat", "dog"}; String[] res = os.getSemanticContentByKeywords(params); for (String s : res) System.out.println(s); } public void rsearch() throws RemoteException{ System.out.println("***** Searching Cat and Dog restricted to local name, label and comments of classes and individuals*****"); String[] params = {"cat", "dog"}; String[] res = os.getSemanticContentByKeywordsWithRestrictions(params, WatsonService.LOCAL_NAME+WatsonService.LABEL+WatsonService.COMMENT, WatsonService.CLASS+WatsonService.INDIVIDUAL, WatsonService.EXACT_MATCH); for (String s : res) System.out.println(s); } public void rsearchp() throws RemoteException{ System.out.println("***** Searching Cat and Dog Paginated *****"); String[] params = {"cat", "dog"}; String[] res = os.getSemanticContentByKeywordsWithRestrictionsPaginated(params, WatsonService.LOCAL_NAME+WatsonService.LABEL+WatsonService.COMMENT, WatsonService.PROPERTY+WatsonService.INDIVIDUAL, WatsonService.TOKEN_MATCH, 0, 11); for (String s : res) System.out.println(s); } private void bestCoverage() throws RemoteException{ System.out.println("***** Searching best coverage of \"mammal man woman child god\", restricted to local name and label of Classes*****"); String[] params = {"mammal", "man", "woman", "child", "god"}; String[] res = os.getBestCoverageWithRestrictions(params, WatsonService.LOCAL_NAME+WatsonService.LABEL, WatsonService.CLASS, WatsonService.TOKEN_MATCH); for (String s : res) System.out.println(s); } public void listSC() throws RemoteException { System.out.println("***** Listing Semantic Contents (can take a while...) *****"); for (int i = 0 ; i < 30000; i+=1000) { String[] res = os.listSemanticContents(i, i+1000); for (String s : res) System.out.println(s); } } public void locations() throws RemoteException{ System.out.println("***** Location(s) of sane_cows.daml *****"); String[] res = os.getSemanticContentLocation("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml"); for (String r : res) System.out.println(r); } public void cacheLocation() throws RemoteException{ System.out.println("***** Cache Location of sane_cows.daml *****"); String res = os.getCacheLocation("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml"); System.out.println(res); } /* Have not been deployed in the new version... public void OWLSpecy() throws RemoteException{ System.out.println("***** OWL Species of Mid-level-ontology *****"); // TODO: change to int and change the name String res = os.getOWLSpecy("http://reliant.teknowledge.com/DAML/Mid-level-ontology.owl"); if (Integer.parseInt(res) == FULL) System.out.println("OWL Full"); if (Integer.parseInt(res) == DL) System.out.println("OWL DL"); if (Integer.parseInt(res) == LITE) System.out.println("OWL Lite"); if (Integer.parseInt(res) == NOT_OWL || Integer.parseInt(res) == -1) System.out.println("N/A"); }*/ public void DLExpr() throws RemoteException{ System.out.println("***** DL Expr of sane_cows.daml *****"); String res = os.getDLExpressivness("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml"); System.out.println(res); } public void size() throws RemoteException{ System.out.println("***** Size in bytes of sane_cows.daml *****"); long res = os.getSizeInBytes("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml"); System.out.println(res); } public void languages() throws RemoteException{ System.out.println("***** Languages of sane_cows.daml *****"); String[] res = os.getSemanticContentLanguages("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml"); for (String s : res) System.out.println(s); } public void listClasses() throws RemoteException{ System.out.println("***** Classes of sane_cows.daml *****"); String[] res = os.listClasses("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml"); for (String s : res) System.out.println(s); } public void listProperties() throws RemoteException{ System.out.println("***** Properties of sane_cows.daml *****"); String[] res = os.listProperties("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml"); for (String s : res) System.out.println(s); } public void listIndividuals() throws RemoteException{ System.out.println("***** Individuals of sane_cows.daml *****"); String[] res = os.listIndividuals("http://www.aktors.org/ontology/support.daml"); for (String s : res) System.out.println(s); } public void nbReviews() throws RemoteException{ System.out.println("***** Number of reviews for http://owl.man.ac.uk/tutorial/twopets.rdf *****"); int nb = os.getNumberOfReviews("http://owl.man.ac.uk/tutorial/twopets.rdf"); System.out.println(nb); } public void avgReviews() throws RemoteException{ System.out.println("***** Number of reviews for http://owl.man.ac.uk/tutorial/twopets.rdf *****"); int nb = os.getAverageRating("http://owl.man.ac.uk/tutorial/twopets.rdf"); System.out.println(nb); } public void revyuURI() throws RemoteException{ System.out.println("***** Number of reviews for http://owl.man.ac.uk/tutorial/twopets.rdf *****"); String uri = os.getRevyuURL("http://owl.man.ac.uk/tutorial/twopets.rdf"); System.out.println(uri); } public void sparql() throws RemoteException{ System.out.println("***** Executing a SPARQL query sane_cows.daml (get labels) *****"); String query = "PREFIX rdfs: " + "PREFIX rdf: " + "PREFIX owl: " + "PREFIX daml: " + "SELECT ?s ?o " + "WHERE " + "{ ?s rdfs:label ?o } " ; String res = os.executeSPARQLQuery("http://www.cs.man.ac.uk/~horrocks/ESSLLI2003/Ontologies/sane_cows.daml", query); System.out.println(res); } public void imports() throws RemoteException{ System.out.println("***** Ontology imported by http://www.aktors.org/ontology/portal *****"); String[] res = os.getImports("http://www.aktors.org/ontology/portal"); for (String s : res) System.out.println(s); } public void imported() throws RemoteException{ System.out.println("***** Ontology importing by http://www.aktors.org/ontology/portal *****"); String[] res = os.getImportedBy("http://www.aktors.org/ontology/portal"); for (String s : res) System.out.println(s); } public void labels() throws RemoteException{ System.out.println("***** Labels of http://www.aktors.org/ontology/portal *****"); String[] res = os.getLabels("http://www.aktors.org/ontology/portal"); for (String s : res) System.out.println(s); } public void comments() throws RemoteException{ System.out.println("***** Cpmments of http://www.mindswap.org/2003/owl/pet *****"); String[] res = os.getLabels("http://www.mindswap.org/2003/owl/pet"); for (String s : res) System.out.println(s); } public void nbstats() throws RemoteException{ System.out.println("***** NBStats of http://www.mindswap.org/2003/owl/pet *****"); long s = os.getNumberOfStatement("http://www.mindswap.org/2003/owl/pet"); System.out.println(s); } }