comparison src/de/mpiwg/itgroup/triplestoremanager/tools/GenerateLandingPage.java @ 3:6c8dac2c5214

New tools export graph and generate landing page of an echo ressource
author dwinter
date Thu, 21 Jun 2012 12:24:29 +0200
parents
children
comparison
equal deleted inserted replaced
2:221a0fd0a5d3 3:6c8dac2c5214
1 package de.mpiwg.itgroup.triplestoremanager.tools;
2
3 import java.io.FileWriter;
4 import java.io.IOException;
5
6 import org.openrdf.model.Resource;
7 import org.openrdf.model.Statement;
8 import org.openrdf.model.Value;
9 import org.openrdf.model.impl.ContextStatementImpl;
10 import org.openrdf.model.impl.URIImpl;
11 import org.openrdf.query.Binding;
12 import org.openrdf.query.BindingSet;
13 import org.openrdf.query.MalformedQueryException;
14 import org.openrdf.query.QueryEvaluationException;
15 import org.openrdf.query.TupleQueryResult;
16 import org.openrdf.rio.RDFHandlerException;
17 import org.openrdf.rio.trig.TriGWriter;
18
19 import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException;
20 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler;
21
22 public class GenerateLandingPage {
23
24 /**
25 * @param args
26 */
27
28 public static void main(String args[]) throws TripleStoreHandlerException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
29 //TripleStoreHandler th = new TripleStoreHandler(
30 // "jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1112", args[0], args[1]);
31
32
33 FileWriter fw = new FileWriter("/tmp/lp.ttl");
34 TriGWriter turtleWriter = new TriGWriter(fw);
35 turtleWriter.startRDF();
36 if (args.length<3){
37 System.out.println("Usage: connection String user password");
38 System.out.println("eg: jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111 user password");
39 System.exit(1);
40 }
41 TripleStoreHandler th = new TripleStoreHandler(
42 args[0], args[1], args[2]);
43
44 String qs = String.format("select ?entity where {?entity a <http://ontologies.mpiwg-berlin.mpg.de/general/IndexMeta>}");
45
46 TupleQueryResult res = th.querySPARQL(qs);
47
48
49 while(res.hasNext()){
50 BindingSet bs = res.next();
51 Binding entity = bs.getBinding("entity");
52
53 URIImpl y = new URIImpl("http://ontologies.mpiwg-berlin.mpg.de/general/hasLandingPage");
54 URIImpl z =(URIImpl)entity.getValue();
55 URIImpl z2= new URIImpl(z.toString().replace("/indexMeta", ""));
56
57 URIImpl g = new URIImpl("http://indexMeta_ECHOE_landingPages");
58
59 Statement stm = new ContextStatementImpl((Resource)entity.getValue(), y, z2,g);
60
61 turtleWriter.handleStatement(stm);
62 }
63 turtleWriter.endRDF();
64 fw.close();
65 }
66 }
67