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