Project

General

Profile

« Previous | Next » 

Revision 8692

switch to the OpenAnnotation (OA) model for annotating datapackages with measurements/characteristics (semtools)

View differences:

metacat-index/src/main/resources/application-context-annotation.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="/d100: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/test/java/edu/ucsb/nceas/metacat/index/SolrIndexIT.java
42 42
    
43 43
	private String annotation_id = "http://doi.org/annotation.1.1";
44 44
	private static final String ANNOTATION_SYSTEM_META_FILE_PATH = "src/test/resources/annotation-system-meta-example.xml";
45
	private static final String ANNOTATION_FILE_PATH = "src/test/resources/annotation-example.rdf";;
46
    
45
	private static final String AO_FILE_PATH = "src/test/resources/ao-example.rdf";;
46
	private static final String OA_FILE_PATH = "src/test/resources/oa-example.rdf";;
47

  
47 48
	private SolrIndex solrIndex = null;
48 49
    
49 50
    @Before
......
190 191
    }
191 192
    
192 193
    /**
193
     * Test building index for annotation.
194
     * Test building index for annotation using OpenAnnotation.
194 195
     */
195 196
    @Test
196
    public void testAnnotation() throws Exception {
197
    public void testOpenAnnotation() throws Exception {
197 198
    	
198 199
       SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAFILEPATH);
199 200
       InputStream emlInputStream = new FileInputStream(new File(EMLFILEPATH)); 
......
213 214
       
214 215
       // augment with the dynamic field
215 216
       SystemMetadata annotationSystemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, ANNOTATION_SYSTEM_META_FILE_PATH);
216
       InputStream annotationInputStream = new FileInputStream(new File(ANNOTATION_FILE_PATH)); 
217
       InputStream annotationInputStream = new FileInputStream(new File(OA_FILE_PATH)); 
217 218
       Identifier annotationPid = new Identifier();
218 219
       annotationPid.setValue(annotation_id);
219 220
       solrIndex.update(annotationPid, annotationSystemMetadata, annotationInputStream);
220 221
       String annotationResult = doQuery(solrIndex.getSolrServer());
221
       assertTrue(annotationResult.contains("measurement_sm"));
222
       assertTrue(annotationResult.contains("characteristic_sm"));
222 223
       
223 224
    }
224 225
    
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/annotation/RdfXmlSubprocessor.java
151 151
						solrDoc = documentsToIndex.get(id);
152 152
						if (solrDoc == null) {
153 153
							solrDoc = new SolrDoc();
154
							solrDoc.addField(new SolrElementField(SolrElementField.FIELD_ID, id));
154 155
							documentsToIndex.put(id, solrDoc);
155 156
						}
156 157
					}
......
208 209
    		}
209 210
    		// add the pending
210 211
    		for (SolrElementField field: pendingDoc.getFieldList()) {
212
    			if (field.getName().equals(SolrElementField.FIELD_ID) && mergedDoc.hasField(SolrElementField.FIELD_ID)) {
213
    				continue;
214
    			}
211 215
				mergedDoc.addField(field);
212 216
				
213 217
			}
......
221 225
	 * Get the SolrDoc for the specified id
222 226
	 */
223 227
	public static SolrDoc getSolrDoc(String id) throws SolrServerException, MalformedURLException, UnsupportedType, NotFound, ParserConfigurationException, IOException, SAXException {
224
		SolrDoc doc = new SolrDoc();
228
		SolrDoc doc = null;
225 229

  
226 230
		if (solrServer != null) {
227 231
			String query = QUERY + "\"" + id + "\"";
228 232
			SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
229 233
			QueryResponse qr = solrServer.query(solrParams);
230
			SolrDocument orig = qr.getResults().get(0);
231
			IndexSchema indexSchema = SolrQueryServiceController.getInstance().getSchema();
232
			for (String fieldName : orig.getFieldNames()) {
233
				// don't transfer the copyTo fields, otherwise there are errors
234
				if (indexSchema.isCopyFieldTarget(indexSchema.getField(fieldName))) {
235
					continue;
236
				}
237
				for (Object value : orig.getFieldValues(fieldName)) {
238
					String stringValue = value.toString();
239
					// special handling for dates in ISO 8601
240
					if (value instanceof Date) {
241
						stringValue = DateTimeMarshaller.serializeDateToUTC((Date) value);
242
						SolrDateConverter converter = new SolrDateConverter();
243
						stringValue = converter.convert(stringValue);
234
			if (!qr.getResults().isEmpty()) {
235
				doc = new SolrDoc();
236
				SolrDocument orig = qr.getResults().get(0);
237
				IndexSchema indexSchema = SolrQueryServiceController.getInstance().getSchema();
238
				for (String fieldName : orig.getFieldNames()) {
239
					// don't transfer the copyTo fields, otherwise there are errors
240
					if (indexSchema.isCopyFieldTarget(indexSchema.getField(fieldName))) {
241
						continue;
244 242
					}
245
					SolrElementField field = new SolrElementField(fieldName, stringValue);
246
					log.debug("Adding field: " + fieldName);
247
					doc.addField(field);
243
					for (Object value : orig.getFieldValues(fieldName)) {
244
						String stringValue = value.toString();
245
						// special handling for dates in ISO 8601
246
						if (value instanceof Date) {
247
							stringValue = DateTimeMarshaller.serializeDateToUTC((Date) value);
248
							SolrDateConverter converter = new SolrDateConverter();
249
							stringValue = converter.convert(stringValue);
250
						}
251
						SolrElementField field = new SolrElementField(fieldName, stringValue);
252
						log.debug("Adding field: " + fieldName);
253
						doc.addField(field);
254
					}
248 255
				}
249 256
			}
250 257

  
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="/d100: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>
0 62

  
metacat-index/src/main/resources/application-context-oa.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="/d100: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="characteristic_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 oa: <http://www.w3.org/ns/oa#>
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 ?characteristic_sm ?pid
31
				FROM <$GRAPH_NAME>
32
				WHERE { 
33
						
34
						?measurement rdf:type oboe-core:Measurement .
35
						?measurement rdf:type ?restriction .
36
						?restriction owl:onProperty oboe-core:ofCharacteristic .
37
						?restriction owl:allValuesFrom ?characteristic .
38
						?characteristic rdfs:subClassOf+ ?characteristic_sm .
39
						?characteristic_sm rdfs:subClassOf oboe-core:Characteristic .
40
						
41
						OPTIONAL { 
42
							?measurement rdf:type ?restriction2 .
43
							?restriction2 owl:onProperty oboe-core:usesStandard .
44
							?restriction2 owl:allValuesFrom ?standard .
45
						}
46
						
47
						?annotation oa:hasBody ?measurement .
48
						?annotation oa:hasTarget ?target .
49
						?target oa:hasSource ?metadata .
50
						?metadata dcterms:identifier ?pid . 
51
						
52
						?annotation oa:annotatedBy ?person .
53
						?person foaf:name ?name .
54
				 	} 
55
				 ]]>
56
			</value>
57
		</constructor-arg>
58
		<!--property name="multivalue" value="false" /-->
59
	</bean>
60

  
61
</beans>
0 62

  
metacat-index/src/main/resources/index-processor-context.xml
27 27
    <import resource="application-context-resource-map.xml" />
28 28
    <import resource="application-context-systemmeta100.xml" />
29 29
    
30
    <import resource="application-context-annotation.xml" />
30
    <import resource="application-context-oa.xml" />
31
    
32
    <!-- <import resource="application-context-ao.xml" /> -->
33
    
31 34

  
32 35
 <bean id="dateConverter" class="org.dataone.cn.indexer.convert.SolrDateConverter" />
33 36
 <bean id="fgdcDateConverter" class="org.dataone.cn.indexer.convert.FgdcDateConverter"/>

Also available in: Unified diff