Project

General

Profile

« Previous | Next » 

Revision 51043

Playing with inference rules on the remote sparql endpoint

View differences:

modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoTest.java
3 3
import java.io.IOException;
4 4
import java.io.InputStream;
5 5
import java.io.UnsupportedEncodingException;
6
import java.net.URLEncoder;
7 6

  
8 7
import org.apache.jena.graph.NodeFactory;
9 8
import org.apache.jena.graph.Triple;
......
42 41
	private String testUser = "dba";
43 42
	private String testPwd = "dba";
44 43
	private String defaultURIBaseURl = "http://test/";
44
	private String sparqlEndpoint = "http://localhost:8890/sparql";
45 45

  
46 46
	@Before
47 47
	public void prepare() {
......
50 50
		graph.clear();
51 51
	}
52 52

  
53
	/**
54
	 * See also: https://stackoverflow.com/questions/24576190/enable-reasoning-for-sparql-request-via-jena
55
	 */
53 56
	@Test
57
	public void testInference1(){
58
		String q = "DEFINE input:inference 'parthenos_rules' CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
59
		String subjectURL = "http://clarin.eu/clarin-eric-datatables/centres";
60
		String query = String.format(q, subjectURL, subjectURL, subjectURL, subjectURL);
61
		System.out.println(query);
62
		final QueryEngineHTTP request = new QueryEngineHTTP (sparqlEndpoint, query);
63
		Model res = request.execConstruct();
64
		RDFDataMgr.write(System.out, res, RDFFormat.RDFXML_PLAIN);
65
		res.close();
66
		request.close();
67
	}
68

  
69

  
70

  
71
	@Test
54 72
	public void testRemote() throws UnsupportedEncodingException {
55 73
		//Note that we still get 406 when this code is executed by VirtuosoReadApi on the Virtuoso server of Parthenos.
56
		String q = "DEFINE input:inference <parthenos_rules> CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
74
		String q = "DEFINE input:inference 'parthenos_rules' CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
57 75
		//String q = "CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
58
		String subjectURL = URLEncoder.encode("http://clarin.eu/clarin-eric-datatables/centres", "UTF-8");
76
		String subjectURL = "http://clarin.eu/clarin-eric-datatables/centres";
59 77
		String query = String.format(q, subjectURL, subjectURL, subjectURL, subjectURL);
78
		System.out.println(query);
60 79
		VirtGraph g = new VirtGraph(connectionString, testUser, testPwd);
61 80
		g.setReadFromAllGraphs(true);
62 81
		VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create(query, g);
......
276 295

  
277 296

  
278 297

  
298

  
279 299
	private InputStream getResourceAsStream(final String classpath) {
280 300
		try {
281 301
			final ClassPathResource resource = new ClassPathResource(classpath);
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoReadAPI.java
53 53
	private String password;
54 54
	@Value("${virtuoso.uri.base.default}")
55 55
	private String defaultBaseURI;
56
	@Value("${virtuoso.connectionstring")
57
	private String virtuosoConnectionString;
56 58

  
57 59
	@Autowired
58 60
	private Configuration freemarkerConfig;
......
116 118
		//log.debug(describeQuery);
117 119
		//Can't use DESCRIBE query: server decides what to return (i.e. not all triples) and cannot find out if and how Virtuoso can be configured
118 120

  
119
		//String q = "DEFINE input:inference <parthenos_rules> CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
120
		String q = "CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o . }";
121
		String q = "DEFINE input:inference 'parthenos_rules' CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
122
		//String q = "CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o . }";
121 123
		String query = String.format(q, subjectURL, subjectURL, subjectURL, subjectURL);
122 124
		sendConstructResponse(QueryFactory.create(query), responseStream);
123 125

  
......
141 143

  
142 144
	protected void sendConstructResponse(final Query query, final OutputStream responseStream){
143 145
		log.debug(query);
144
		final QueryEngineHTTP serviceRequest = QueryExecutionFactory.createServiceRequest(sparqlUrl, query);
146
		final QueryEngineHTTP serviceRequest = new QueryEngineHTTP(sparqlUrl, query);
145 147
		Model resultModel = serviceRequest.execConstruct();
146 148
		RDFDataMgr.write(responseStream, resultModel, RDFFormat.RDFXML_PLAIN);
147 149
		serviceRequest.close();
150

  
148 151
	}
149 152

  
150 153

  

Also available in: Unified diff