Mercurial > hg > duomoOWLProject
annotate src/de/mpiwg/dwinter/duomo/lexdump/LexOWLTransformer.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 | 30fc93374f10 |
rev | line source |
---|---|
0 | 1 package de.mpiwg.dwinter.duomo.lexdump; |
2 | |
1 | 3 import java.io.File; |
4 import java.io.FileWriter; | |
0 | 5 import java.io.IOException; |
6 import java.net.URI; | |
7 import java.net.URISyntaxException; | |
8 import java.net.URLEncoder; | |
9 import java.util.Collection; | |
10 import java.util.HashMap; | |
11 import java.util.HashSet; | |
12 import java.util.Iterator; | |
13 import java.util.List; | |
14 import java.util.Map; | |
15 import java.util.Set; | |
16 | |
17 import javax.print.URIException; | |
18 | |
19 import org.apache.log4j.Level; | |
20 import org.apache.log4j.Logger; | |
21 import org.jdom.Attribute; | |
22 import org.jdom.Element; | |
23 import org.jdom.JDOMException; | |
24 import org.jdom.xpath.XPath; | |
25 | |
26 import com.sun.xml.internal.ws.developer.MemberSubmissionEndpointReference.Elements; | |
27 | |
28 import edu.stanford.smi.protege.exception.OntologyLoadException; | |
29 import edu.stanford.smi.protege.model.Instance; | |
4 | 30 import edu.stanford.smi.protegex.owl.jena.JenaOWLModel; |
0 | 31 import edu.stanford.smi.protegex.owl.model.OWLAllValuesFrom; |
32 import edu.stanford.smi.protegex.owl.model.OWLClass; | |
33 import edu.stanford.smi.protegex.owl.model.OWLDataRange; | |
34 import edu.stanford.smi.protegex.owl.model.OWLIndividual; | |
35 import edu.stanford.smi.protegex.owl.model.OWLNamedClass; | |
36 import edu.stanford.smi.protegex.owl.model.OWLProperty; | |
37 import edu.stanford.smi.protegex.owl.model.OWLUnionClass; | |
38 import edu.stanford.smi.protegex.owl.model.RDFList; | |
39 import edu.stanford.smi.protegex.owl.model.RDFProperty; | |
40 import edu.stanford.smi.protegex.owl.model.RDFResource; | |
41 import edu.stanford.smi.protegex.owl.model.impl.AbstractOWLQuantifierRestriction; | |
42 import edu.stanford.smi.protegex.owl.model.impl.DefaultOWLUnionClass; | |
43 | |
44 public class LexOWLTransformer { | |
45 private Logger logger = Logger.getRootLogger(); | |
1 | 46 private FileWriter missing; |
0 | 47 private OWLImporter owlDoc; |
48 private LexDumpImporter lexDoc; | |
49 private Map<String, OWLIndividual> individualIds = new HashMap<String, OWLIndividual>(); // speichere | |
50 // ids | |
51 // fuer | |
52 // weitere | |
53 // Verwendung | |
54 | |
1 | 55 public LexOWLTransformer(OWLImporter owlDoc, LexDumpImporter lexDoc) throws IOException { |
0 | 56 this.owlDoc = owlDoc; |
57 this.lexDoc = lexDoc; | |
2 | 58 missing = new FileWriter(new File("/tmp/missing.out")); |
0 | 59 } |
60 | |
61 /** | |
62 * @param args | |
63 * @throws Exception | |
64 */ | |
65 public static void main(String[] args) throws Exception { | |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
66 System.out.println("Stack size has to be large, use at lease -Xss=2024k!"); |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
67 if (args.length<2){ |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
68 System.out.println("Usage: \"/Users/dwinter/Documents/Projekte/Diss - data-mining/eclipseWorkspace/de.mpiwg.dwinter.duomo/owlInput\""+ |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
69 "\"/Users/dwinter/Documents/Projekte/Diss - data-mining/eclipseWorkspace/duomoData/LEXXDUMP.xml\""); |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
70 System.exit(-1); |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
71 } |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
72 |
0 | 73 Logger.getRootLogger().setLevel(Level.DEBUG); |
74 // Import OWL | |
75 //String base = "/Users/dwinter/Documents/Projekte/Diss - data-mining/eclipseWorkspace/de.mpiwg.dwinter.duomo/owlInput"; | |
76 String base=args[0]; | |
77 String baseUri= base.replace(" ", "%20"); | |
78 URI ontologieUri = new URI("file://"+baseUri+"/duomoAnalysis.owl"); | |
79 //URI ontologieUri = new URI( | |
80 // "file:///Users/dwinter/Documents/Projekte/Diss%20-%20data-mining/eclipseWorkspace/de.mpiwg.dwinter.duomo/owlInput/duomoAnalysis.owl"); | |
81 OWLImporter owlDoc = null; | |
82 try { | |
83 | |
84 owlDoc = new OWLImporter(base, ontologieUri); | |
85 // owlDoc.printModel(); | |
86 } catch (OntologyLoadException e) { | |
87 e.printStackTrace(); | |
88 System.exit(-1); | |
89 } | |
90 // read and parse lexfile | |
91 //String lexFile = "/Users/dwinter/Documents/Projekte/Diss - data-mining/eclipseWorkspace/duomoData/LEXXDUMP.xml"; | |
92 String lexFile=args[1]; | |
93 LexDumpImporter lexDoc = null; | |
94 try { | |
95 lexDoc = new LexDumpImporter(lexFile); | |
96 } catch (JDOMException e) { | |
97 e.printStackTrace(); | |
98 System.exit(-1); | |
99 } catch (IOException e) { | |
100 System.exit(-1); | |
101 e.printStackTrace(); | |
102 } | |
103 | |
104 // List<Element> cartas = lexDoc.getCartas(); | |
105 // System.out.println(cartas.size()); | |
106 | |
107 LexOWLTransformer tf = new LexOWLTransformer(owlDoc, lexDoc); | |
108 tf.transform(); | |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
109 owlDoc.save("file:///tmp/out.owl"); |
0 | 110 } |
111 | |
4 | 112 private void transform() throws URISyntaxException, Exception { |
0 | 113 List<Element> signatures = lexDoc.getSignatures(); |
114 | |
115 // Element signature = signatures.get(0); | |
4 | 116 int signatureCount = 0; |
0 | 117 int maxsign = signatures.size(); |
118 for (Element signature : signatures) { | |
119 logger.debug(String.format("Signature: %s (%s)", signatureCount, | |
120 maxsign)); | |
4 | 121 |
122 signatureCount++; | |
123 //if (signatureCount<5 || signatureCount>10) | |
124 // continue; | |
0 | 125 OWLIndividual signatureInd = createSignature(signature); |
126 | |
127 @SuppressWarnings("unchecked") | |
128 List<Element> cards = XPath.selectNodes(signature, ".//carta"); | |
129 int cardsCount = 1; | |
130 int maxcards = cards.size(); | |
131 | |
132 // Element card=cards.get(0); | |
133 for (Element card : cards) { | |
134 logger.debug(String.format("Cards: %s (%s)", cardsCount++, | |
135 maxcards)); | |
136 logger.debug(String.format("Signature: %s (%s)", | |
137 signatureCount, maxsign)); | |
138 OWLIndividual cardInd = createCard(card, signatureInd); | |
139 | |
140 @SuppressWarnings("unchecked") | |
141 List<Element> records = XPath.selectNodes(card, ".//record"); | |
142 for (Element record : records) { | |
143 // Element record = records.get(0); | |
144 OWLIndividual recordInd = createRecord(record, cardInd); | |
145 OWLIndividual recordEvent = createEvent(record, recordInd); // Event | |
146 // und | |
147 // Records | |
148 // sind | |
149 // im | |
150 // Original | |
151 // im | |
152 // record-tag | |
153 } | |
154 } | |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
155 //owlDoc.save("file:///tmp/out"+String.valueOf(signatureCount)+".owl"); |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
156 //logger.debug("Saved:"+"/tmp/out"+String.valueOf(signatureCount)+".owl"); |
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
157 //owlDoc.reloadOWL(); |
0 | 158 } |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
159 owlDoc.printModel(); |
0 | 160 } |
161 | |
162 private OWLIndividual createEvent(Element record, OWLIndividual recordInd) { | |
163 | |
164 logger.debug("Create Event"); | |
165 OWLIndividual eventInstance = owlDoc.createInstance("RecordedEvent"); | |
166 | |
167 owlDoc.setProperty(recordInd, "crm:P70_documents", eventInstance); | |
168 | |
169 // timespan | |
170 | |
171 try { | |
172 String dateDcStart = lexDoc.getValue(record, ".//datdf/startdate"); | |
173 | |
174 String dateDcEnd = lexDoc.getValue(record, ".//datdf/startdate"); | |
175 | |
176 if (!dateDcStart.equals("")) { | |
177 OWLIndividual timeSpan = owlDoc.createTimeSpan(dateDcStart, | |
178 dateDcEnd); | |
179 owlDoc.setProperty(eventInstance, "crm:P4_has_time-span", | |
180 timeSpan); | |
181 } | |
182 } catch (JDOMException e) { | |
183 // TODO Auto-generated catch block | |
184 e.printStackTrace(); | |
185 } | |
186 | |
187 // tipol | |
188 String typology; | |
189 try { | |
190 typology = lexDoc.getValue(record, ".//tipol"); | |
191 OWLIndividual typolInd = createOrGetTipol(typology); | |
192 owlDoc.setProperty(eventInstance, "has_tipol", typolInd); | |
193 | |
194 } catch (JDOMException e) { | |
195 // TODO Auto-generated catch block | |
196 e.printStackTrace(); | |
197 } | |
198 | |
199 // reges | |
200 try { | |
201 createNewDependingDataTypePropertyFromXpath(record, eventInstance, | |
202 ".//reges/italian", "has_reges", "it"); | |
203 createNewDependingDataTypePropertyFromXpath(record, eventInstance, | |
204 ".//reges/english", "has_reges", "en"); | |
205 } catch (JDOMException e) { | |
206 // TODO Auto-generated catch block | |
207 e.printStackTrace(); | |
208 } | |
209 | |
210 // nomiq | |
211 | |
212 try { | |
213 @SuppressWarnings("unchecked") | |
214 List<Element> nomiqs = XPath.selectNodes(record, ".//nomiq"); | |
215 OWLIndividual recordNamesRoles = null; | |
216 for (Element nomiq : nomiqs) { | |
217 String name = lexDoc.getValue(nomiq, "./name"); | |
218 String role = lexDoc.getValue(nomiq, "./role"); | |
219 | |
220 if (!name.equals("") && !role.equals("")) { | |
221 recordNamesRoles = handleNameWithRole(recordInd, name, role); | |
222 } else if (!role.equals("")) { | |
2 | 223 recordNamesRoles = createOrGetRole(role); |
0 | 224 } else if (!name.equals("")) { |
2 | 225 recordNamesRoles = createOrGetName(name); |
0 | 226 } |
227 | |
228 if (recordNamesRoles != null) { | |
229 owlDoc.setProperty(eventInstance, | |
230 "recordsDuomoObjectNameRoles", recordNamesRoles); | |
231 String id = lexDoc.getValue(nomiq, "./@id"); | |
232 individualIds.put(id, recordNamesRoles); | |
233 } | |
234 } | |
235 | |
236 } catch (JDOMException e) { | |
237 // TODO Auto-generated catch block | |
238 e.printStackTrace(); | |
239 } | |
240 | |
241 // istit | |
242 try { | |
243 String istit = lexDoc.getValue(record, "./istit"); | |
244 OWLIndividual istitInd = owlDoc.getIndividualByReadableId( | |
245 "IndicesInstitutions", istit); | |
246 if (istitInd == null) { | |
247 istitInd = createOrGetInstitution(istit); | |
248 } | |
249 | |
250 owlDoc.setProperty(eventInstance, "recordsDuomoObjectInstitution", | |
251 istitInd); | |
252 | |
253 } catch (JDOMException e) { | |
254 // TODO Auto-generated catch block | |
255 e.printStackTrace(); | |
256 } | |
257 | |
258 // types | |
259 | |
260 try { | |
261 List<Element> types = XPath.selectNodes(record, ".//type"); | |
262 for (Element type : types) { | |
263 createType(eventInstance, type); | |
264 } | |
265 } catch (JDOMException e) { | |
266 // TODO Auto-generated catch block | |
267 e.printStackTrace(); | |
268 } | |
269 | |
270 return eventInstance; | |
271 } | |
272 | |
273 private void createType(OWLIndividual eventInstance, Element type) { | |
274 | |
275 String typeId; | |
276 try { | |
277 typeId = lexDoc.getValue(type, "./ptr/@target"); | |
278 String clsName = owlDoc.getClassNameFromTypeId(typeId); | |
279 OWLNamedClass cls = owlDoc.getClassFromTypeId(typeId); | |
280 OWLIndividual typeInd = owlDoc.createInstance(clsName); | |
281 | |
282 OWLNamedClass subjectClass = getPreferredTargetClass(cls, | |
283 "has_subject"); | |
284 OWLNamedClass predicateClass = getPreferredTargetClass(cls, | |
285 "has_predicate"); | |
286 | |
287 List<Element> freeTexts = XPath.selectNodes(type, "./freetext"); | |
288 for (Element freeText : freeTexts) { | |
289 | |
290 String subjPointer = lexDoc.getValue(freeText, | |
291 "./sub/ptrtoperson/@target"); | |
292 String subjText = lexDoc.getValue(freeText, "./sub"); | |
293 | |
294 OWLIndividual subjInd = createSubjectOrPredicate(subjectClass, | |
295 subjPointer, subjText); | |
296 | |
297 String predPointer = lexDoc.getValue(freeText, | |
298 "./pred/ptrtoperson/@target"); | |
299 String predText = lexDoc.getValue(freeText, "./pred"); | |
300 | |
301 OWLIndividual predInd = createSubjectOrPredicate( | |
302 predicateClass, predPointer, predText); | |
303 | |
304 if (subjInd != null) { | |
305 owlDoc.setProperty(typeInd, "has_subject", subjInd); | |
306 } | |
307 | |
308 if (predInd != null) { | |
309 owlDoc.setProperty(typeInd, "has_predicate", predInd); | |
310 } | |
311 | |
312 owlDoc.setProperty(eventInstance, "recordsDuomoObjectConcept", | |
313 typeInd); | |
314 } | |
315 | |
316 } catch (JDOMException e) { | |
317 // TODO Auto-generated catch block | |
318 e.printStackTrace(); | |
319 } | |
320 | |
321 } | |
322 | |
323 private OWLIndividual createSubjectOrPredicate(OWLNamedClass toClass, | |
324 String subjPointer, String subjText) { | |
325 OWLIndividual subjInd = null; | |
326 | |
327 if (!subjPointer.equals("")) { | |
328 subjInd = toClass.createOWLIndividual(null); | |
329 OWLIndividual ind = individualIds.get(subjPointer); | |
330 if (ind == null) { | |
331 logger.debug("target ID does not exist:" + subjPointer); | |
1 | 332 try { |
333 missing.write("target ID does not exist:" + subjPointer+"\n"); | |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
334 missing.flush(); |
1 | 335 } catch (IOException e) { |
336 // TODO Auto-generated catch block | |
337 e.printStackTrace(); | |
338 } | |
0 | 339 } else { |
340 owlDoc.setProperty(subjInd, "has_NameOrRoleFromIndex", ind); | |
341 } | |
342 } | |
343 | |
344 if (!subjText.equals("")) { | |
345 if (subjInd == null) | |
346 subjInd = toClass.createOWLIndividual(null); | |
347 | |
348 OWLNamedClass idcls = owlDoc.owlModel | |
349 .getOWLNamedClass("Identifier"); // is die klasse selbst | |
350 // schon ein identifiert | |
351 if (toClass.getNamedSuperclasses(true).contains(idcls)) { // to | |
352 owlDoc.setProperty(subjInd, "has_readable_id", subjText); | |
353 } else { | |
354 | |
355 OWLIndividual ident = owlDoc | |
356 .createInstance("IdentifierPredicateOrSubject"); | |
357 owlDoc.setProperty(ident, "has_readable_id", subjText); | |
358 owlDoc.setProperty(subjInd, "crm:P48_has_preferred_identifier", | |
359 ident); | |
360 } | |
361 } | |
362 return subjInd; | |
363 } | |
364 | |
365 private OWLNamedClass getPreferredTargetClass(OWLNamedClass cls, | |
366 String propertyName) { | |
367 RDFProperty prop = owlDoc.owlModel.getRDFProperty(propertyName); | |
368 | |
369 // finde welche klasse als subject erlaubt ist | |
370 Collection<?> restrictions = cls.getRestrictions(prop, true); | |
371 | |
372 RDFResource restrictionValues = prop.getRange(); // nimm erstmal den | |
373 // gesammten Range | |
374 | |
375 // schaue jetzt nach ob eb es einschraenkungen gibt. | |
376 for (Iterator<?> it = restrictions.iterator(); it.hasNext();) { | |
377 Object restriction = it.next(); | |
378 if (OWLAllValuesFrom.class.isInstance(restriction)) { | |
379 OWLAllValuesFrom ar = (OWLAllValuesFrom) restriction; | |
380 restrictionValues = ar.getAllValuesFrom(); | |
381 break; | |
382 } | |
383 | |
384 } | |
385 OWLNamedClass toClass = null; | |
386 if (OWLNamedClass.class.isInstance(restrictionValues)) { | |
387 toClass = (OWLNamedClass) restrictionValues; | |
388 } else if (OWLDataRange.class.isInstance(restrictionValues)) { | |
389 RDFList dr = ((OWLDataRange) restrictionValues).getOneOf(); | |
390 for (Object d : dr.getValues()) { | |
391 System.out.println(d); | |
392 toClass = (OWLNamedClass) d; | |
393 // FIXME: geht das?? | |
394 } | |
395 } else if (DefaultOWLUnionClass.class.isInstance(restrictionValues)) { // mehr | |
396 // als | |
397 // eine | |
398 // moeglich | |
399 DefaultOWLUnionClass ou = (DefaultOWLUnionClass) restrictionValues; | |
400 Set set = new HashSet(); | |
401 ou.getNestedNamedClasses(set); | |
402 | |
403 for (Iterator<?> it = set.iterator(); it.hasNext();) { | |
404 OWLNamedClass cl = (OWLNamedClass) it.next(); | |
405 OWLNamedClass idcls = owlDoc.owlModel | |
406 .getOWLNamedClass("Identifier"); // nimm die Klasse die | |
407 // ein Identifier | |
408 // ist. | |
409 if (cl.getNamedSuperclasses(true).contains(idcls)) { | |
410 toClass = cl; | |
411 break; | |
412 } | |
413 | |
414 } | |
415 } | |
416 return toClass; | |
417 } | |
418 | |
2 | 419 |
0 | 420 |
421 private OWLIndividual handleNameWithRole(OWLIndividual recordInd, | |
422 String name, String role) { | |
423 // teste ob schon ein solcer Eintrag existiert | |
424 OWLIndividual nameInd = owlDoc.getIndividualByReadableId( | |
425 "IndicesNames", name); | |
426 Boolean createNewNameWithRole = false; | |
427 if (nameInd == null) { | |
428 nameInd = createOrGetName(name); | |
429 createNewNameWithRole = true; // name existierte nicht dann kann | |
430 // auch NameWithRole nicht | |
431 // existierten. | |
432 } | |
433 OWLIndividual roleInd = owlDoc.getIndividualByReadableId( | |
434 "IndicesRoles", role); | |
435 if (roleInd == null) { | |
2 | 436 roleInd = createOrGetRole(role); |
0 | 437 createNewNameWithRole = true; // role existierte nicht dann kann |
438 // auch NameWithRole nicht | |
439 // existierten. | |
440 } | |
441 OWLIndividual nameWithRoleInd = null; | |
442 if (!createNewNameWithRole) { // schon klar, dass er nicht existiert | |
443 nameWithRoleInd = getNameWithRole(nameInd, roleInd); | |
444 } | |
445 | |
446 if (nameWithRoleInd == null) { // existiert nicht | |
447 nameWithRoleInd = createNameWithRole(nameInd, roleInd); | |
448 } | |
449 | |
450 return nameWithRoleInd; | |
451 } | |
452 | |
453 private OWLIndividual getNameWithRole(OWLIndividual nameInd, | |
454 OWLIndividual roleInd) { | |
455 List<OWLIndividual> indicesWithNames = owlDoc.getIndividuals( | |
456 "IndicesNameWithRole", "refers_to_name", nameInd); // suche alle | |
457 // infrage | |
458 // kommenden | |
459 // nameen | |
460 | |
461 if (indicesWithNames == null) { // kein Treffer | |
462 return null; | |
463 } | |
464 | |
465 for (OWLIndividual name : indicesWithNames) { | |
466 Object role = owlDoc.getRelatedIndividual(name, "refers_to_role"); | |
467 if (roleInd.equals(role)) { | |
468 return name; | |
469 } | |
470 } | |
471 return null; | |
472 } | |
473 | |
474 private OWLIndividual createOrGetTipol(String typology) { | |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
475 OWLIndividual tipol = owlDoc.createOrGetInstanceWithIdentifier("Typology","Identifier",typology,false); |
0 | 476 return tipol; |
477 } | |
478 | |
479 private OWLIndividual createNameWithRole(OWLIndividual nameInd, | |
480 OWLIndividual roleInd) { | |
481 | |
482 OWLIndividual nameWithRoleInd = owlDoc | |
483 .createInstance("IndicesNameWithRole"); | |
484 | |
485 owlDoc.setProperty(nameWithRoleInd, "refers_to_name", nameInd); | |
486 owlDoc.setProperty(nameWithRoleInd, "refers_to_role", roleInd); | |
487 | |
488 return nameWithRoleInd; | |
489 | |
490 } | |
491 | |
492 private OWLIndividual createOrGetInstitution(String name) { | |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
493 OWLIndividual nameInd = owlDoc.createOrGetInstanceWithIdentifier("IndicesInstitutions","IdentifierInstitutions",name,false); |
0 | 494 |
495 return nameInd; | |
496 } | |
497 | |
498 private OWLIndividual createOrGetName(String name) { | |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
499 OWLIndividual nameInd = owlDoc.createOrGetInstanceWithIdentifier("IndicesNames","IdentifierNames",name,false); |
0 | 500 return nameInd; |
501 } | |
502 | |
2 | 503 private OWLIndividual createOrGetRole(String name) { |
5
923e73fa07f1
Minor changes, Suche nach Objekten nach readableId jetzt einschraenkbar, nicht auf subclassen ausweiten.
dwinter
parents:
4
diff
changeset
|
504 OWLIndividual roleInd = owlDoc.createOrGetInstanceWithIdentifier("IndicesRoles","IdentifierRoles",name,false); |
0 | 505 return roleInd; |
506 } | |
507 | |
508 private OWLIndividual createRecord(Element record, OWLIndividual cardInd) | |
509 throws JDOMException { | |
510 OWLIndividual recordInstance = owlDoc.createInstance("Record"); | |
511 owlDoc.setProperty(recordInstance, "is_on_card", cardInd); | |
512 createNewDependingInstanceFromXpath(record, recordInstance, "./@id", | |
513 new String[] { "has_readable_id", "rdfs:label" }, | |
514 "IdentifierCurrent", "crm:P48_has_preferred_identifier"); | |
515 | |
516 String value = lexDoc.getValue(record, ".//textblockid"); | |
517 if (!value.equals("")) | |
518 owlDoc.setProperty(recordInstance, "has_textblockid", value); | |
519 | |
520 String endOnCarta = lexDoc.getValue(record, "./@end_on_carta"); | |
521 if (!endOnCarta.equals("")) { | |
522 OWLIndividual signature = (OWLIndividual) owlDoc | |
523 .getRelatedIndividual(cardInd, "has_signature"); | |
524 addRecordToCarta(recordInstance, value, signature); | |
525 } | |
526 | |
527 String dateDcStart = lexDoc.getValue(record, ".//datdc/startdate"); | |
528 String dateDcEnd = lexDoc.getValue(record, ".//datdc/startdate"); | |
529 | |
530 OWLIndividual timeSpan = owlDoc.createTimeSpan(dateDcStart, dateDcEnd); | |
531 | |
532 owlDoc.setProperty(recordInstance, "crm:P4_has_time-span", timeSpan); | |
533 | |
534 return recordInstance; | |
535 } | |
536 | |
537 private void addRecordToCarta(OWLIndividual recordInstance, String cardID, | |
538 OWLIndividual signature) { | |
539 | |
540 OWLIndividual card = owlDoc.getIndividualByReadableId("Card", cardID); | |
541 | |
542 if (card == null) { | |
543 card = createCard(cardID, signature); | |
544 } | |
545 | |
546 owlDoc.setProperty(recordInstance, "is_on_card", card); | |
547 } | |
548 | |
549 private OWLIndividual createSignature(Element signature) | |
550 throws JDOMException { | |
551 Element segHeaderElement = (Element) XPath.selectSingleNode(signature, | |
552 ".//segheader"); | |
553 String segheader = segHeaderElement.getTextTrim(); | |
554 | |
555 OWLIndividual signatureInstance = owlDoc.createInstance("Signatur"); | |
556 owlDoc.setProperty(signatureInstance, "rdfs:label", segheader); | |
557 return signatureInstance; | |
558 } | |
559 | |
560 private OWLIndividual createCard(String cardId, OWLIndividual signature) { | |
561 | |
562 OWLIndividual cardInstance = owlDoc.createInstance("Card"); | |
563 | |
564 owlDoc.setProperty(cardInstance, "has_signature", signature); | |
565 | |
566 OWLIndividual preferredId = owlDoc.createInstance("IdentifierCurrent"); | |
567 owlDoc.setProperty(preferredId, "has_readable_id", cardId); | |
568 owlDoc.setProperty(preferredId, "rdfs:label", cardId); | |
569 | |
570 owlDoc.setProperty(cardInstance, "crm:P48_has_preferred_identifier", | |
571 preferredId); | |
572 | |
573 return cardInstance; | |
574 } | |
575 | |
576 private OWLIndividual createCard(Element card, OWLIndividual signatureInd) { | |
577 | |
578 OWLIndividual cardInstance = owlDoc.createInstance("Card"); | |
579 | |
580 try { | |
581 | |
582 createNewDependingInstanceFromXpath(card, cardInstance, | |
583 ".//cartanr", new String[] { "has_readable_id", | |
584 "rdfs:label" }, "IdentifierCurrent", | |
585 "crm:P48_has_preferred_identifier"); | |
586 | |
587 createNewDependingInstanceFromXpath(card, cardInstance, | |
588 ".//cartaant", new String[] { "has_readable_id", | |
589 "rdfs:label" }, "IdentifierCurrent", | |
590 "crm:P1_is_identified_by"); | |
591 | |
592 owlDoc.setProperty(cardInstance, "has_signature", signatureInd); | |
593 | |
594 } catch (JDOMException e) { | |
595 e.printStackTrace(); | |
596 return null; | |
597 } | |
598 | |
599 return cardInstance; | |
600 } | |
601 | |
602 private void createNewDependingInstanceFromXpath(Element card, | |
603 OWLIndividual cardInstance, String xpath, String[] propertyNames, | |
604 String newInstanceClassName, String relationNameToNewInstance) | |
605 throws JDOMException { | |
606 | |
607 List<?> identifierIdEls = (List<?>) XPath.selectNodes(card, xpath); | |
608 for (Object identifierIdEl : identifierIdEls) { | |
609 String identifierId = ""; | |
610 if (Element.class.isInstance(identifierIdEl)) { | |
611 identifierId = ((Element) identifierIdEl).getTextTrim(); | |
612 } else if (Attribute.class.isInstance(identifierIdEl)) { | |
613 identifierId = ((Attribute) identifierIdEl).getValue(); | |
614 } | |
615 | |
616 OWLIndividual identifier = owlDoc | |
617 .createInstance(newInstanceClassName); | |
618 for (int i = 0; i < propertyNames.length; i++) { | |
619 owlDoc.setProperty(identifier, propertyNames[i], identifierId); | |
620 } | |
621 | |
622 owlDoc.setProperty(cardInstance, relationNameToNewInstance, | |
623 identifier); | |
624 } | |
625 | |
626 } | |
627 | |
628 // createNewDependingDataTypePropertyFromXpath(record, eventInstance, | |
629 // ".//resges/italian", "has_reges", | |
630 // "italian"); | |
631 private void createNewDependingDataTypePropertyFromXpath(Element record, | |
632 OWLIndividual eventInstance, String xpath, String propertyName, | |
633 String lang) throws JDOMException { | |
634 | |
635 List<?> identifierIdEls = (List<?>) XPath.selectNodes(record, xpath); | |
636 for (Object identifierIdEl : identifierIdEls) { | |
637 String identifierId = ""; | |
638 if (Element.class.isInstance(identifierIdEl)) { | |
639 identifierId = ((Element) identifierIdEl).getTextTrim(); | |
640 } else if (Attribute.class.isInstance(identifierIdEl)) { | |
641 identifierId = ((Attribute) identifierIdEl).getValue(); | |
642 } | |
643 | |
644 owlDoc.setDataTypePropery(eventInstance, propertyName, | |
645 identifierId, lang); | |
646 } | |
647 } | |
648 } |