Project

General

Profile

« Previous | Next » 

Revision 8769

cache the imported models to avoid timeouts from remote hosts (or being locked out for too many requests in a given time period).

View differences:

src/edu/ucsb/nceas/metacat/annotation/DatapackageSummarizer.java
28 28
import com.hp.hpl.jena.ontology.Individual;
29 29
import com.hp.hpl.jena.ontology.ObjectProperty;
30 30
import com.hp.hpl.jena.ontology.OntClass;
31
import com.hp.hpl.jena.ontology.OntDocumentManager;
31 32
import com.hp.hpl.jena.ontology.OntModel;
32 33
import com.hp.hpl.jena.ontology.Ontology;
33 34
import com.hp.hpl.jena.query.Dataset;
34
import com.hp.hpl.jena.query.DatasetFactory;
35 35
import com.hp.hpl.jena.query.Query;
36 36
import com.hp.hpl.jena.query.QueryExecution;
37 37
import com.hp.hpl.jena.query.QueryExecutionFactory;
......
78 78
    public static String cito =  "http://purl.org/spar/cito/";
79 79
    
80 80
	public static String OBOE_SBC = "OBOE-SBC";
81
	
82
	private static boolean cacheInitialized;
83
	
84
	private static void initializeCache() {
85
		if (!cacheInitialized) {
86
			// cache the ontologies we use
87
			OntDocumentManager.getInstance().addModel(oboe, ModelFactory.createOntologyModel().read(oboe));
88
			OntDocumentManager.getInstance().addModel(oboe_sbc, ModelFactory.createOntologyModel().read(oboe_sbc));
89
			OntDocumentManager.getInstance().addModel(oa, ModelFactory.createOntologyModel().read(oa_source));
90
			OntDocumentManager.getInstance().addModel(dcterms, ModelFactory.createOntologyModel().read(dcterms_source));
91
			OntDocumentManager.getInstance().addModel(foaf, ModelFactory.createOntologyModel().read(foaf_source));
92
			OntDocumentManager.getInstance().addModel(prov, ModelFactory.createOntologyModel().read(prov));
93
			OntDocumentManager.getInstance().addModel(cito, ModelFactory.createOntologyModel().read(cito));
94
			cacheInitialized = true;
95
		}
96
	}
81 97
    
82 98
    public void indexEphemeralAnnotation(Identifier metadataPid) throws Exception {
83 99

  
......
216 232
		Ontology ont = m.createOntology("http://annotation/" + metadataPid.getValue());
217 233
		
218 234
		// TODO: import the ontologies we use
235
		initializeCache();
236
		
219 237
		ont.addImport(m.createResource(oboe));
220
		m.addSubModel(ModelFactory.createOntologyModel().read(oboe));
238
		m.addSubModel(OntDocumentManager.getInstance().getModel(oboe));
221 239
		
222 240
		ont.addImport(m.createResource(oboe_sbc));
223
		m.addSubModel(ModelFactory.createOntologyModel().read(oboe_sbc));
241
		m.addSubModel(OntDocumentManager.getInstance().getModel(oboe_sbc));
224 242
		
225 243
		ont.addImport(m.createResource(oa));
226
		m.addSubModel(ModelFactory.createOntologyModel().read(oa_source));
244
		m.addSubModel(OntDocumentManager.getInstance().getModel(oa));
227 245

  
228 246
		ont.addImport(m.createResource(dcterms));
229
		m.addSubModel(ModelFactory.createOntologyModel().read(dcterms_source));
247
		m.addSubModel(OntDocumentManager.getInstance().getModel(dcterms));
230 248

  
231 249
		ont.addImport(m.createResource(foaf));
232
		m.addSubModel(ModelFactory.createOntologyModel().read(foaf_source));
250
		m.addSubModel(OntDocumentManager.getInstance().getModel(foaf));
233 251
		
234 252
		ont.addImport(m.createResource(prov));
235 253
		//m.addSubModel(ModelFactory.createOntologyModel().read(prov_source));

Also available in: Unified diff