01: /*
02: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: */
06:
07: package arq.examples;
08:
09: import com.hp.hpl.jena.sparql.util.StringUtils;
10: import com.hp.hpl.jena.sparql.util.Utils;
11: import com.hp.hpl.jena.query.ARQ;
12: import com.hp.hpl.jena.query.larq.IndexLARQ;
13: import com.hp.hpl.jena.rdf.model.Model;
14: import com.hp.hpl.jena.rdf.model.ModelFactory;
15:
16: /** Example code to load a model from a file,
17: * index all string literals,
18: * then execute a SPARQL query with a Lucene search in it that
19: * finds which documents have DC titles
20: *
21: * @author Andy Seaborne
22: */
23:
24: public class ExLucene2 {
25:
26: public static void main(String[] a) throws Exception {
27: System.out.println("ARQ Example: "
28: + Utils.classShortName(ExLucene2.class));
29: System.out.println("ARQ: " + ARQ.VERSION);
30: System.out.println();
31:
32: Model model = ModelFactory.createDefaultModel();
33: IndexLARQ index = ExLucene1.buildIndex(model,
34: "testing/LARQ/data-1.ttl");
35:
36: // Search for string
37: String searchString = "+document";
38:
39: // This time, find documents with a matching DC title.
40: String queryString = StringUtils
41: .join(
42: "\n",
43: new String[] {
44: "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>",
45: "PREFIX : <http://example/>",
46: "PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>",
47: "PREFIX dc: <http://purl.org/dc/elements/1.1/>",
48: "SELECT ?doc ?title {",
49: " ?title pf:textMatch '"
50: + searchString + "'.",
51: " ?doc dc:title ?title", "}" });
52:
53: // Two of three documents should match.
54: ExLucene1.performQuery(model, index, queryString);
55: index.close();
56: }
57: }
58:
59: /*
60: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
61: * All rights reserved.
62: *
63: * Redistribution and use in source and binary forms, with or without
64: * modification, are permitted provided that the following conditions
65: * are met:
66: * 1. Redistributions of source code must retain the above copyright
67: * notice, this list of conditions and the following disclaimer.
68: * 2. Redistributions in binary form must reproduce the above copyright
69: * notice, this list of conditions and the following disclaimer in the
70: * documentation and/or other materials provided with the distribution.
71: * 3. The name of the author may not be used to endorse or promote products
72: * derived from this software without specific prior written permission.
73: *
74: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84: */
|