Revision 8973
Added by ben leinfelder about 10 years ago
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/annotation/TripleStoreService.java | ||
---|---|---|
1 |
package edu.ucsb.nceas.metacat.index.annotation; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import com.hp.hpl.jena.query.Dataset; |
|
6 |
import com.hp.hpl.jena.tdb.TDBFactory; |
|
7 |
|
|
8 |
public class TripleStoreService { |
|
9 |
|
|
10 |
private static TripleStoreService instance; |
|
11 |
|
|
12 |
private TripleStoreService() {} |
|
13 |
|
|
14 |
public static TripleStoreService getInstance() { |
|
15 |
if (instance == null) { |
|
16 |
instance = new TripleStoreService(); |
|
17 |
} |
|
18 |
return instance; |
|
19 |
} |
|
20 |
|
|
21 |
public Dataset getDataset() { |
|
22 |
String directory = "./tdb"; |
|
23 |
|
|
24 |
// for testing, delete the triplestore each time |
|
25 |
File dir = new File(directory); |
|
26 |
// if (dir.exists()) { |
|
27 |
// dir.delete(); |
|
28 |
// } |
|
29 |
Dataset dataset = TDBFactory.createDataset(directory); |
|
30 |
return dataset; |
|
31 |
} |
|
32 |
} |
|
33 | 0 |
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/annotation/SparqlField.java | ||
---|---|---|
1 |
package edu.ucsb.nceas.metacat.index.annotation; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import javax.xml.xpath.XPath; |
|
6 |
|
|
7 |
import org.dataone.cn.indexer.parser.ISolrField; |
|
8 |
import org.dataone.cn.indexer.solrhttp.SolrElementField; |
|
9 |
import org.w3c.dom.Document; |
|
10 |
|
|
11 |
public class SparqlField implements ISolrField { |
|
12 |
|
|
13 |
private String name; |
|
14 |
|
|
15 |
private String query; |
|
16 |
|
|
17 |
public SparqlField(String name, String query) { |
|
18 |
this.name = name; |
|
19 |
this.query = query; |
|
20 |
} |
|
21 |
|
|
22 |
public String getName() { |
|
23 |
return name; |
|
24 |
} |
|
25 |
|
|
26 |
public void setName(String name) { |
|
27 |
this.name = name; |
|
28 |
} |
|
29 |
|
|
30 |
public String getQuery() { |
|
31 |
return query; |
|
32 |
} |
|
33 |
|
|
34 |
public void setQuery(String query) { |
|
35 |
this.query = query; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public List<SolrElementField> getFields(Document arg0, String arg1) |
|
40 |
throws Exception { |
|
41 |
// TODO Auto-generated method stub |
|
42 |
return null; |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public void initExpression(XPath arg0) { |
|
47 |
// TODO Auto-generated method stub |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
} |
|
52 | 0 |
metacat-index/src/main/resources/application-context-ao.xml | ||
---|---|---|
1 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
2 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xmlns:p="http://www.springframework.org/schema/p" |
|
4 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> |
|
5 |
|
|
6 |
<bean id="rdfXmlSubprocessor" class="edu.ucsb.nceas.metacat.index.annotation.RdfXmlSubprocessor"> |
|
7 |
<property name="matchDocument" |
|
8 |
value="/d200:systemMetadata/formatId[text()='http://www.w3.org/TR/rdf-syntax-grammar']" /> |
|
9 |
<property name="fieldList"> |
|
10 |
<list> |
|
11 |
<ref bean="annotation.measurement" /> |
|
12 |
</list> |
|
13 |
</property> |
|
14 |
</bean> |
|
15 |
|
|
16 |
<bean id="annotation.measurement" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField"> |
|
17 |
<constructor-arg name="name" value="measurement_sm" /> |
|
18 |
<constructor-arg name="query"> |
|
19 |
<value> |
|
20 |
<![CDATA[ |
|
21 |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
|
22 |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
|
23 |
PREFIX owl: <http://www.w3.org/2002/07/owl#> |
|
24 |
PREFIX oboe-core: <http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#> |
|
25 |
PREFIX ao: <http://purl.org/ao/> |
|
26 |
PREFIX dcterms: <http://purl.org/dc/terms/> |
|
27 |
PREFIX pav: <http://purl.org/pav/> |
|
28 |
PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
|
29 |
|
|
30 |
SELECT ?measurement_sm ?pid |
|
31 |
FROM <$GRAPH_NAME> |
|
32 |
WHERE { |
|
33 |
|
|
34 |
?measurement_sm rdf:type oboe-core:Measurement . |
|
35 |
?measurement_sm rdf:type ?restriction . |
|
36 |
?restriction owl:onProperty oboe-core:ofCharacteristic . |
|
37 |
?restriction owl:allValuesFrom ?characteristic . |
|
38 |
?characteristic rdfs:subClassOf+ ?allChar . |
|
39 |
?allChar rdfs:subClassOf oboe-core:Characteristic . |
|
40 |
|
|
41 |
OPTIONAL { |
|
42 |
?measurement_sm rdf:type ?restriction2 . |
|
43 |
?restriction2 owl:onProperty oboe-core:usesStandard . |
|
44 |
?restriction2 owl:allValuesFrom ?standard . |
|
45 |
} |
|
46 |
|
|
47 |
?annotation ao:context ?measurement_sm . |
|
48 |
?annotation ao:annotatesResource ?metadata . |
|
49 |
?metadata dcterms:identifier ?pid . |
|
50 |
|
|
51 |
?annotation pav:createdBy ?person . |
|
52 |
?person foaf:name ?name . |
|
53 |
?annotation pav:createdOn ?date . |
|
54 |
} |
|
55 |
]]> |
|
56 |
</value> |
|
57 |
</constructor-arg> |
|
58 |
<!--property name="multivalue" value="false" /--> |
|
59 |
</bean> |
|
60 |
|
|
61 |
</beans> |
|
62 | 0 |
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/annotation/RdfXmlSubprocessor.java | ||
---|---|---|
21 | 21 |
import java.io.InputStream; |
22 | 22 |
import java.net.MalformedURLException; |
23 | 23 |
import java.net.URI; |
24 |
import java.net.URISyntaxException; |
|
25 | 24 |
import java.util.ArrayList; |
26 | 25 |
import java.util.Arrays; |
27 | 26 |
import java.util.Date; |
... | ... | |
51 | 50 |
import org.apache.solr.common.params.SolrParams; |
52 | 51 |
import org.apache.solr.schema.IndexSchema; |
53 | 52 |
import org.apache.solr.servlet.SolrRequestParsers; |
53 |
import org.dataone.cn.indexer.annotation.SparqlField; |
|
54 |
import org.dataone.cn.indexer.annotation.TripleStoreService; |
|
54 | 55 |
import org.dataone.cn.indexer.convert.SolrDateConverter; |
55 | 56 |
import org.dataone.cn.indexer.parser.AbstractDocumentSubprocessor; |
56 | 57 |
import org.dataone.cn.indexer.parser.IDocumentSubprocessor; |
metacat-index/src/main/resources/application-context-oa.xml | ||
---|---|---|
19 | 19 |
</property> |
20 | 20 |
</bean> |
21 | 21 |
|
22 |
<bean id="annotation.standard" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField">
|
|
22 |
<bean id="annotation.standard" class="org.dataone.cn.indexer.annotation.SparqlField">
|
|
23 | 23 |
<constructor-arg name="name" value="standard_sm" /> |
24 | 24 |
<constructor-arg name="query"> |
25 | 25 |
<value> |
... | ... | |
54 | 54 |
<!--property name="multivalue" value="false" /--> |
55 | 55 |
</bean> |
56 | 56 |
|
57 |
<bean id="annotation.characteristic" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField">
|
|
57 |
<bean id="annotation.characteristic" class="org.dataone.cn.indexer.annotation.SparqlField">
|
|
58 | 58 |
<constructor-arg name="name" value="characteristic_sm" /> |
59 | 59 |
<constructor-arg name="query"> |
60 | 60 |
<value> |
... | ... | |
89 | 89 |
<!--property name="multivalue" value="false" /--> |
90 | 90 |
</bean> |
91 | 91 |
|
92 |
<bean id="annotation.creator" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField">
|
|
92 |
<bean id="annotation.creator" class="org.dataone.cn.indexer.annotation.SparqlField">
|
|
93 | 93 |
<constructor-arg name="name" value="creator_sm" /> |
94 | 94 |
<constructor-arg name="query"> |
95 | 95 |
<value> |
... | ... | |
116 | 116 |
<!--property name="multivalue" value="false" /--> |
117 | 117 |
</bean> |
118 | 118 |
|
119 |
<bean id="prov.wasDerivedFrom" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField">
|
|
119 |
<bean id="prov.wasDerivedFrom" class="org.dataone.cn.indexer.annotation.SparqlField">
|
|
120 | 120 |
<constructor-arg name="name" value="wasDerivedFrom" /> |
121 | 121 |
<constructor-arg name="query"> |
122 | 122 |
<value> |
... | ... | |
142 | 142 |
</constructor-arg> |
143 | 143 |
</bean> |
144 | 144 |
|
145 |
<bean id="prov.wasGeneratedBy" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField">
|
|
145 |
<bean id="prov.wasGeneratedBy" class="org.dataone.cn.indexer.annotation.SparqlField">
|
|
146 | 146 |
<constructor-arg name="name" value="wasGeneratedBy" /> |
147 | 147 |
<constructor-arg name="query"> |
148 | 148 |
<value> |
... | ... | |
168 | 168 |
</constructor-arg> |
169 | 169 |
</bean> |
170 | 170 |
|
171 |
<bean id="prov.wasInformedBy" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField">
|
|
171 |
<bean id="prov.wasInformedBy" class="org.dataone.cn.indexer.annotation.SparqlField">
|
|
172 | 172 |
<constructor-arg name="name" value="wasInformedBy" /> |
173 | 173 |
<constructor-arg name="query"> |
174 | 174 |
<value> |
... | ... | |
194 | 194 |
</constructor-arg> |
195 | 195 |
</bean> |
196 | 196 |
|
197 |
<bean id="prov.used" class="edu.ucsb.nceas.metacat.index.annotation.SparqlField">
|
|
197 |
<bean id="prov.used" class="org.dataone.cn.indexer.annotation.SparqlField">
|
|
198 | 198 |
<constructor-arg name="name" value="used" /> |
199 | 199 |
<constructor-arg name="query"> |
200 | 200 |
<value> |
metacat-index/src/main/resources/index-processor-context.xml | ||
---|---|---|
29 | 29 |
|
30 | 30 |
|
31 | 31 |
<import resource="application-context-oa.xml" /> |
32 |
<import resource="application-context-annotator.xml" /> |
|
33 |
|
|
34 |
|
|
35 |
<!-- <import resource="application-context-ao.xml" /> --> |
|
36 |
|
|
32 |
<import resource="application-context-annotator.xml" /> |
|
37 | 33 |
|
38 | 34 |
<bean id="dateConverter" class="org.dataone.cn.indexer.convert.SolrDateConverter" /> |
39 | 35 |
<bean id="fgdcDateConverter" class="org.dataone.cn.indexer.convert.FgdcDateConverter"/> |
metacat-index/src/main/resources/application-context-annotator.xml | ||
---|---|---|
3 | 3 |
xmlns:p="http://www.springframework.org/schema/p" |
4 | 4 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> |
5 | 5 |
|
6 |
<bean id="annotatorSubprocessor" class="org.dataone.cn.indexer.annotation.AnnotatorSubprocessor"/> |
|
7 |
<!-- no params needed for this processor yet --> |
|
6 |
<bean id="annotatorSubprocessor" class="org.dataone.cn.indexer.annotation.AnnotatorSubprocessor"> |
|
7 |
|
|
8 |
<!-- match any document type --> |
|
9 |
<property name="matchDocument" |
|
10 |
value="/d200:systemMetadata/formatId[text() != '']" /> |
|
11 |
<property name="fieldList"> |
|
12 |
<list> |
|
13 |
<ref bean="annotation.expansion" /> |
|
14 |
</list> |
|
15 |
</property> |
|
16 |
</bean> |
|
17 |
|
|
18 |
<bean id="annotation.expansion" class="org.dataone.cn.indexer.annotation.SparqlField"> |
|
19 |
<constructor-arg name="name" value="annotation_sm" /> |
|
20 |
<constructor-arg name="query"> |
|
21 |
<value> |
|
22 |
<![CDATA[ |
|
23 |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
|
24 |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
|
25 |
PREFIX owl: <http://www.w3.org/2002/07/owl#> |
|
26 |
|
|
27 |
SELECT ?annotation_sm |
|
28 |
FROM <$GRAPH_NAME> |
|
29 |
WHERE { |
|
30 |
<$CONCEPT_URI> rdfs:subClassOf+ ?annotation_sm . |
|
31 |
} |
|
32 |
]]> |
|
33 |
</value> |
|
34 |
</constructor-arg> |
|
35 |
<!--property name="multivalue" value="false" /--> |
|
36 |
</bean> |
|
8 | 37 |
|
9 | 38 |
</beans> |
Also available in: Unified diff
use sparql field and triple store from cn-index_processor (refactor). include annotatorSubprocessor for testing in metacat-index