1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| package com.ontotext.wsmo4j.parser.wsml; |
27 |
| |
28 |
| import java.util.*; |
29 |
| |
30 |
| import org.omwg.logicalexpression.terms.*; |
31 |
| import org.omwg.ontology.*; |
32 |
| import org.wsmo.common.*; |
33 |
| import org.wsmo.common.exception.*; |
34 |
| import org.wsmo.wsml.compiler.node.*; |
35 |
| |
36 |
| import com.ontotext.wsmo4j.parser.*; |
37 |
| |
38 |
| public class NFPAnalysis extends ASTAnalysis { |
39 |
| |
40 |
| private Stack termsStack; |
41 |
| private Stack identifierStack; |
42 |
| private Stack entityStack; |
43 |
| |
44 |
0
| public NFPAnalysis(ASTAnalysisContainer container) {
|
45 |
0
| if (container == null) {
|
46 |
0
| throw new IllegalArgumentException();
|
47 |
| } |
48 |
0
| termsStack = container.getStack(Term[].class);
|
49 |
0
| identifierStack = container.getStack(Identifier.class);
|
50 |
0
| entityStack = container.getStack(Entity.class);
|
51 |
| |
52 |
| |
53 |
0
| container.registerNodeHandler(ANfp.class, this);
|
54 |
0
| container.registerNodeHandler(PNfp.class, this);
|
55 |
| } |
56 |
| |
57 |
| private Object rootIdentifier; |
58 |
| private Object rootTerm; |
59 |
| |
60 |
0
| public void inANfp(ANfp node) {
|
61 |
| |
62 |
0
| if (!termsStack.isEmpty())
|
63 |
0
| rootTerm = termsStack.peek();
|
64 |
| else |
65 |
0
| rootTerm = null;
|
66 |
0
| if (!identifierStack.isEmpty())
|
67 |
0
| rootIdentifier = identifierStack.peek();
|
68 |
| else |
69 |
0
| rootIdentifier = null;
|
70 |
| } |
71 |
| |
72 |
0
| public void outANfp(ANfp node) {
|
73 |
0
| if (entityStack.isEmpty()) {
|
74 |
0
| return;
|
75 |
| } |
76 |
0
| Entity entity = (Entity) entityStack.peek();
|
77 |
| |
78 |
0
| try {
|
79 |
0
| Term[] terms = null;
|
80 |
0
| while (!identifierStack.isEmpty() &&
|
81 |
| identifierStack.peek() != rootIdentifier) { |
82 |
| |
83 |
0
| if (termsStack.isEmpty()) {
|
84 |
0
| throw new RuntimeException("The NFP term queue is shorter then iri queue!");
|
85 |
| } |
86 |
| |
87 |
0
| IRI iri = (IRI) identifierStack.pop();
|
88 |
0
| terms = (Term[]) termsStack.pop();
|
89 |
| |
90 |
0
| for (int i = 0; i < terms.length; i++) {
|
91 |
0
| if (terms[i] instanceof DataValue)
|
92 |
0
| entity.addNFPValue(iri, (DataValue) terms[i]);
|
93 |
| else |
94 |
0
| entity.addNFPValue(iri, (Identifier) terms[i]);
|
95 |
| } |
96 |
| } |
97 |
| |
98 |
| |
99 |
0
| if (!termsStack.isEmpty() &&
|
100 |
| termsStack.peek() != rootTerm) { |
101 |
0
| throw new RuntimeException("The NFP term queue is longer then iri queue!");
|
102 |
| } |
103 |
| } |
104 |
| catch (InvalidModelException ime) { |
105 |
0
| throw new WrappedInvalidModelException(ime);
|
106 |
| } |
107 |
| } |
108 |
| } |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |