| 1 | package org.semanticdesktop.nepomuk.webapp; |
|---|
| 2 | |
|---|
| 3 | import java.util.List; |
|---|
| 4 | |
|---|
| 5 | import org.ontoware.aifbcommons.collection.ClosableIterator; |
|---|
| 6 | import org.ontoware.rdf2go.model.Statement; |
|---|
| 7 | import org.ontoware.rdf2go.model.node.Variable; |
|---|
| 8 | import org.ontoware.rdf2go.vocabulary.RDF; |
|---|
| 9 | import org.semanticdesktop.nepomuk.clientservices.NepomukXmlRpcClient; |
|---|
| 10 | import org.semanticdesktop.services.NepomukServices; |
|---|
| 11 | import org.semanticdesktop.services.rdfrepository.Node; |
|---|
| 12 | import org.semanticdesktop.services.rdfrepository.QueryResultTable; |
|---|
| 13 | import org.semanticdesktop.services.rdfrepository.RDFRepository; |
|---|
| 14 | import org.semanticdesktop.services.rdfrepository.RDFRepositoryConst; |
|---|
| 15 | |
|---|
| 16 | public class ExampleUsage { |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | public static void main(String[] args) throws Exception { |
|---|
| 23 | NepomukXmlRpcClient client = new NepomukXmlRpcClient(); |
|---|
| 24 | NepomukServices services = client; |
|---|
| 25 | System.out.println("And Zarathustra spoke: "+ services.getRdf2gorepository().echo("hello?")); |
|---|
| 26 | System.out.println("So, lets dump 10 random types from the repo "); |
|---|
| 27 | ClosableIterator<? extends Statement> i = services.getRdf2gorepository().getMainRepository(). |
|---|
| 28 | findStatements(Variable.ANY, Variable.ANY, RDF.type, Variable.ANY); |
|---|
| 29 | int c = 0; |
|---|
| 30 | while (i.hasNext() && (c<10)) { |
|---|
| 31 | System.out.println(i.next().toString()); |
|---|
| 32 | c++; |
|---|
| 33 | } |
|---|
| 34 | i.close(); |
|---|
| 35 | System.out.println("The same with RDFRepo"); |
|---|
| 36 | org.semanticdesktop.services.rdfrepository.Statement queryStatement = |
|---|
| 37 | new org.semanticdesktop.services.rdfrepository.Statement( |
|---|
| 38 | new org.semanticdesktop.services.rdfrepository.Node("", RDFRepositoryConst.NULLNODE), |
|---|
| 39 | org.semanticdesktop.services.rdfrepository.Node.createURI(RDF.type.toString()), |
|---|
| 40 | new org.semanticdesktop.services.rdfrepository.Node("", RDFRepositoryConst.NULLNODE), |
|---|
| 41 | new org.semanticdesktop.services.rdfrepository.Node("", RDFRepositoryConst.NULLNODE) |
|---|
| 42 | ); |
|---|
| 43 | List<org.semanticdesktop.services.rdfrepository.Statement> reporesult = client.getRdfrepository().listStatements("main", queryStatement); |
|---|
| 44 | c = 0; |
|---|
| 45 | while (i.hasNext() && (c<10) && (c<reporesult.size())) { |
|---|
| 46 | System.out.println(reporesult.get(c)); |
|---|
| 47 | c++; |
|---|
| 48 | } |
|---|
| 49 | System.out.println("A select query for all classes:"); |
|---|
| 50 | { |
|---|
| 51 | QueryResultTable result = client.getRdfrepository().select(RDFRepository.MAIN_REPOSITORY_ID, |
|---|
| 52 | "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" |
|---|
| 53 | + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" |
|---|
| 54 | + "SELECT ?x WHERE {?x rdf:type rdfs:Class}", "sparql"); |
|---|
| 55 | List<List<Node>> rows = result.getRows(); |
|---|
| 56 | for (List<Node> row : rows) |
|---|
| 57 | { |
|---|
| 58 | for (Node node:row){ |
|---|
| 59 | System.out.print(node.toString()+" | "); |
|---|
| 60 | } |
|---|
| 61 | System.out.println(); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | System.err.flush(); |
|---|
| 65 | System.out.flush(); |
|---|
| 66 | System.out.print("Creating a new class: "); |
|---|
| 67 | String starship = services.getPimoservice().createClass("Starship"); |
|---|
| 68 | System.out.println(starship); |
|---|
| 69 | System.out.print("Creating the NCC 1701: "); |
|---|
| 70 | String enterprise = services.getPimoservice().createResource("Enterprise NCC 1701", starship); |
|---|
| 71 | System.out.println(enterprise); |
|---|
| 72 | System.out.println("Deleting the NCC 1701."); |
|---|
| 73 | services.getPimoservice().deleteResource(enterprise); |
|---|
| 74 | System.out.println("Deleting the new class."); |
|---|
| 75 | services.getPimoservice().deleteClass(starship); |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | System.out.println("end."); |
|---|
| 79 | |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | } |
|---|