comparison src/de/mpiwg/dwinter/duomo/lexdump/OWLImporter.java @ 5:923e73fa07f1

Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
author dwinter
date Mon, 07 Feb 2011 16:51:38 +0100
parents 72004a788198
children 19e40abb3e8a
comparison
equal deleted inserted replaced
4:72004a788198 5:923e73fa07f1
1 package de.mpiwg.dwinter.duomo.lexdump; 1 package de.mpiwg.dwinter.duomo.lexdump;
2 2
3 import java.io.File; 3 import java.io.File;
4 import java.io.FileWriter;
5 import java.io.IOException;
4 import java.net.URI; 6 import java.net.URI;
5 import java.net.URISyntaxException; 7 import java.net.URISyntaxException;
6 import java.util.ArrayList; 8 import java.util.ArrayList;
7 import java.util.Collection; 9 import java.util.Collection;
8 import java.util.HashMap; 10 import java.util.HashMap;
28 30
29 public class OWLImporter { 31 public class OWLImporter {
30 32
31 JenaOWLModel owlModel; // contains the model 33 JenaOWLModel owlModel; // contains the model
32 Logger logger = Logger.getRootLogger(); 34 Logger logger = Logger.getRootLogger();
35 FileWriter fh;
33 private HashMap<String, String> typeId2className=null; 36 private HashMap<String, String> typeId2className=null;
34 private HashMap<String, OWLNamedClass> typeId2class=null; 37 private HashMap<String, OWLNamedClass> typeId2class=null;
35 private String ontFolder; 38 private String ontFolder;
36 private URI uri; 39 private URI uri;
37 40
38 public OWLImporter(String folder, URI uri) throws OntologyLoadException { 41 public OWLImporter(String folder, URI uri) throws OntologyLoadException {
39 // owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri); 42 // owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
40 43
41 this.ontFolder=folder; 44 this.ontFolder=folder;
42 this.uri=uri; 45 this.uri=uri;
43 46 try {
47 this.fh= new FileWriter(new File("/tmp/identifier"));
48 } catch (IOException e) {
49 // TODO Auto-generated catch block
50 e.printStackTrace();
51 }
44 loadOWL(folder, uri); 52 loadOWL(folder, uri);
45 } 53 }
46 54
47 public void reloadOWL() throws OntologyLoadException{ 55 public void reloadOWL() throws OntologyLoadException{
48 loadOWL(ontFolder, uri); 56 loadOWL(ontFolder, uri);
140 148
141 Object value = cardInd.getPropertyValue(prop); 149 Object value = cardInd.getPropertyValue(prop);
142 return value; 150 return value;
143 } 151 }
144 152
153
145 public OWLIndividual getIndividual(String classNameFrom, 154 public OWLIndividual getIndividual(String classNameFrom,
146 String propertyNameToClass, String classNameTo, 155 String propertyNameToClass, String classNameTo,
147 String propertyName2, Object value) { 156 String propertyName2, Object value) {
157 return getIndividual(classNameFrom,
158 propertyNameToClass, classNameTo,
159 propertyName2, value, true);
160 }
161
162
163 public OWLIndividual getIndividual(String classNameFrom,
164 String propertyNameToClass, String classNameTo,
165 String propertyName2, Object value,boolean subclasses) {
148 166
149 RDFProperty prop = owlModel.getRDFProperty(propertyName2); 167 RDFProperty prop = owlModel.getRDFProperty(propertyName2);
150 168
151 OWLClass classTo = owlModel.getOWLNamedClass(classNameTo); 169 OWLClass classTo = owlModel.getOWLNamedClass(classNameTo);
152 Collection<?> instances = classTo.getInstances(true); 170 Collection<?> instances = classTo.getInstances(subclasses);
153 OWLIndividual toIv = null; 171 OWLIndividual toIv = null;
154 // Such individiual mit propertyName2 und Wert value 172 // Such individiual mit propertyName2 und Wert value
155 for (Iterator<?> jt = instances.iterator(); jt.hasNext();) { 173 for (Iterator<?> jt = instances.iterator(); jt.hasNext();) {
156 OWLIndividual iv = (OWLIndividual) jt.next(); 174 OWLIndividual iv = (OWLIndividual) jt.next();
157 Object propVal = iv.getPropertyValue(prop); 175 Object propVal = iv.getPropertyValue(prop);
268 286
269 return timeSpan; 287 return timeSpan;
270 } 288 }
271 289
272 public OWLIndividual getIndividualByReadableId(String className,String identifier){ 290 public OWLIndividual getIndividualByReadableId(String className,String identifier){
273 return getIndividual(className, "crm:P48_has_preferred_identifier", "Identifier", "has_readable_id", identifier); 291 return getIndividual(className, "crm:P48_has_preferred_identifier", "Identifier", "has_readable_id", identifier, true);
292 }
293
294 public OWLIndividual getIndividualByReadableId(String className,String identifier, String classNameIdentifier,boolean subclassedIdentifier){
295 return getIndividual(className, "crm:P48_has_preferred_identifier", classNameIdentifier, "has_readable_id", identifier,subclassedIdentifier);
274 } 296 }
275 297
276 public String getClassNameFromTypeId(String typeId) { 298 public String getClassNameFromTypeId(String typeId) {
277 if (typeId2className==null){ // hash nicht angelegt 299 if (typeId2className==null){ // hash nicht angelegt
278 createTypeId2classHashes(); 300 createTypeId2classHashes();
312 owlModel.save(new URI(string)); 334 owlModel.save(new URI(string));
313 335
314 } 336 }
315 337
316 public OWLIndividual createOrGetInstanceWithIdentifier(String classNameInstance, 338 public OWLIndividual createOrGetInstanceWithIdentifier(String classNameInstance,
317 String classNameIdentifier, String identifier) { 339 String classNameIdentifier, String identifier,boolean followSubclasses) {
318 OWLIndividual ind = getIndividualByReadableId(classNameInstance, identifier); 340 OWLIndividual ind = getIndividualByReadableId(classNameInstance, identifier,classNameIdentifier,followSubclasses);
319 if(ind==null){ 341 if(ind==null){
320 ind = createInstance(classNameInstance); 342 ind = createInstance(classNameInstance);
321 OWLIndividual identifierInd = createInstance(classNameIdentifier); 343 OWLIndividual identifierInd = createInstance(classNameIdentifier);
322 setProperty(identifierInd, "has_readable_id", identifier); 344 setProperty(identifierInd, "has_readable_id", identifier);
345 try {
346 fh.write(classNameInstance+" --" +classNameIdentifier+"---"+identifier+"\n");
347 fh.flush();
348 } catch (IOException e) {
349 // TODO Auto-generated catch block
350 e.printStackTrace();
351 }
323 setProperty(ind, "crm:P48_has_preferred_identifier", 352 setProperty(ind, "crm:P48_has_preferred_identifier",
324 identifierInd); 353 identifierInd);
325 } 354 }
326 return ind; 355 return ind;
327 } 356 }