|
3 | 3 | import dev.ikm.ike.tinkarizer.entity.NavigableDatum; |
4 | 4 | import dev.ikm.ike.tinkarizer.entity.NavigableExtract; |
5 | 5 | import dev.ikm.ike.tinkarizer.entity.ViewableDatum; |
6 | | -import dev.ikm.ike.tinkarizer.entity.ViewableExtract; |
7 | 6 | import dev.ikm.tinkar.common.id.PublicIds; |
8 | 7 | import dev.ikm.tinkar.composer.Composer; |
9 | 8 | import dev.ikm.tinkar.composer.Session; |
|
14 | 13 | import dev.ikm.tinkar.composer.template.StatedAxiom; |
15 | 14 | import dev.ikm.tinkar.composer.template.Synonym; |
16 | 15 | import dev.ikm.tinkar.composer.template.USDialect; |
| 16 | +import dev.ikm.tinkar.entity.VersionProxy; |
17 | 17 | import dev.ikm.tinkar.terms.EntityProxy.Concept; |
18 | 18 | import dev.ikm.tinkar.terms.EntityProxy.Semantic; |
19 | 19 | import dev.ikm.tinkar.terms.State; |
|
25 | 25 | import java.util.UUID; |
26 | 26 | import java.util.concurrent.atomic.AtomicInteger; |
27 | 27 |
|
28 | | -public class Loader implements AutoCloseable{ |
| 28 | +public class Loader implements AutoCloseable { |
29 | 29 |
|
30 | 30 | Logger LOG = LoggerFactory.getLogger(Loader.class); |
31 | 31 |
|
@@ -80,89 +80,85 @@ private void init() { |
80 | 80 | .caseSignificance(TinkarTermV2.DESCRIPTION_NOT_CASE_SENSITIVE) |
81 | 81 | .attach((USDialect dialect) -> dialect.acceptability(TinkarTermV2.PREFERRED))) |
82 | 82 | .attach((StatedAxiom stated) -> stated.isA(TinkarTermV2.IDENTIFIER_SOURCE))); |
| 83 | + |
| 84 | + //Attached Root |
| 85 | + Concept eshModel = Concept.make(PublicIds.of(UUID.fromString("f0b69a19-ba4f-4e52-b30e-d998f028f0ab"))); |
| 86 | + Concept esRoot = Concept.make(PublicIds.of(UUID.fromString("47e533f4-a3d8-5d5b-826d-24eb09d1f3ab"))); |
| 87 | + activeSession.compose(new StatedAxiom() |
| 88 | + .isA(eshModel), esRoot); |
83 | 89 | } |
84 | 90 |
|
85 | 91 | public void loadViewableData(List<ViewableDatum> viewableData) { |
| 92 | + viewableData.forEach(data -> { |
| 93 | + Concept concept = Concept.make(PublicIds.of(data.ids())); |
| 94 | + |
| 95 | + //Create Concept Active or Inactive |
| 96 | + if (data.isActive()) { |
| 97 | + activeSession.compose((ConceptAssembler conceptAssembler) -> |
| 98 | + conceptAssembler.publicId(concept.publicId())); |
| 99 | + conceptCounter.incrementAndGet(); |
| 100 | + } else { |
| 101 | + inactiveSession.compose((ConceptAssembler conceptAssembler) -> |
| 102 | + conceptAssembler.publicId(concept.publicId())); |
| 103 | + conceptCounter.incrementAndGet(); |
| 104 | + } |
86 | 105 |
|
| 106 | + //Create FQN Semantic |
| 107 | + Semantic fqn = Semantic.make(PublicIds.newRandom()); |
| 108 | + activeSession.compose(new FullyQualifiedName() |
| 109 | + .semantic(fqn) |
| 110 | + .language(TinkarTermV2.ENGLISH_LANGUAGE) |
| 111 | + .text(data.fqn()) |
| 112 | + .caseSignificance(TinkarTermV2.DESCRIPTION_NOT_CASE_SENSITIVE), concept); |
| 113 | + semanticCounter.incrementAndGet(); |
| 114 | + activeSession.compose(new USDialect().acceptability(TinkarTermV2.PREFERRED), fqn); |
| 115 | + semanticCounter.incrementAndGet(); |
| 116 | + |
| 117 | + //Create SYN Semantic |
| 118 | + Semantic syn = Semantic.make(PublicIds.newRandom()); |
| 119 | + activeSession.compose(new Synonym() |
| 120 | + .semantic(syn) |
| 121 | + .language(TinkarTermV2.ENGLISH_LANGUAGE) |
| 122 | + .text(data.syn().isEmpty() ? data.fqn() : data.syn()) |
| 123 | + .caseSignificance(TinkarTermV2.DESCRIPTION_NOT_CASE_SENSITIVE), concept); |
| 124 | + semanticCounter.incrementAndGet(); |
| 125 | + activeSession.compose(new USDialect().acceptability(TinkarTermV2.PREFERRED), syn); |
| 126 | + semanticCounter.incrementAndGet(); |
| 127 | + |
| 128 | + //Create DEF Semantic |
| 129 | + Semantic def = Semantic.make(PublicIds.newRandom()); |
| 130 | + activeSession.compose(new Definition() |
| 131 | + .semantic(def) |
| 132 | + .language(TinkarTermV2.ENGLISH_LANGUAGE) |
| 133 | + .text(data.def().isEmpty() ? data.fqn() : data.def()) |
| 134 | + .caseSignificance(TinkarTermV2.DESCRIPTION_NOT_CASE_SENSITIVE), concept); |
| 135 | + semanticCounter.incrementAndGet(); |
| 136 | + activeSession.compose(new USDialect().acceptability(TinkarTermV2.PREFERRED), def); |
| 137 | + semanticCounter.incrementAndGet(); |
| 138 | + |
| 139 | + //Create Identifier Semantic |
| 140 | + if (!data.identifier().isEmpty()) { |
| 141 | + activeSession.compose(new Identifier().source(EC_IDENTIFIER_CONCEPT).identifier(data.identifier()), concept); |
| 142 | + semanticCounter.incrementAndGet(); |
| 143 | + } |
| 144 | + }); |
| 145 | + LOG.info("Finish transforming {} Viewable Data", viewableData.size()); |
87 | 146 | } |
88 | 147 |
|
89 | 148 | public void loadNavigableData(List<NavigableDatum> navigableData) { |
90 | | - |
91 | | - } |
92 | | - |
93 | | - public void viewableTransformation(List<ViewableExtract> viewableData) { |
94 | | -// |
95 | | -// for (ViewableExtract data : viewableData) { |
96 | | -// Concept concept = Concept.make(PublicIds.of(data.ids())); |
97 | | -// |
98 | | -// //Create Concept Active or Inactive |
99 | | -// if (data.status()) { |
100 | | -// activeSession.compose((ConceptAssembler conceptAssembler) -> conceptAssembler.publicId(concept.publicId())); |
101 | | -// conceptCounter.incrementAndGet(); |
102 | | -// } else { |
103 | | -// inactiveSession.compose((ConceptAssembler conceptAssembler) -> conceptAssembler.publicId(concept.publicId())); |
104 | | -// conceptCounter.incrementAndGet(); |
105 | | -// } |
106 | | -// |
107 | | -// //Create FQN Semantic |
108 | | -// Semantic fqn = Semantic.make(PublicIds.newRandom()); |
109 | | -// activeSession.compose(new FullyQualifiedName() |
110 | | -// .semantic(fqn) |
111 | | -// .language(TinkarTermV2.ENGLISH_LANGUAGE) |
112 | | -// .text(data.fqn()) |
113 | | -// .caseSignificance(TinkarTermV2.DESCRIPTION_NOT_CASE_SENSITIVE), concept); |
114 | | -// semanticCounter.incrementAndGet(); |
115 | | -// activeSession.compose(new USDialect().acceptability(TinkarTermV2.PREFERRED), fqn); |
116 | | -// semanticCounter.incrementAndGet(); |
117 | | -// |
118 | | -// //Create SYN Semantic |
119 | | -// Semantic syn = Semantic.make(PublicIds.newRandom()); |
120 | | -// activeSession.compose(new Synonym() |
121 | | -// .semantic(syn) |
122 | | -// .language(TinkarTermV2.ENGLISH_LANGUAGE) |
123 | | -// .text(data.syn().isEmpty() ? data.fqn() : data.syn()) |
124 | | -// .caseSignificance(TinkarTermV2.DESCRIPTION_NOT_CASE_SENSITIVE), concept); |
125 | | -// semanticCounter.incrementAndGet(); |
126 | | -// activeSession.compose(new USDialect().acceptability(TinkarTermV2.PREFERRED), syn); |
127 | | -// semanticCounter.incrementAndGet(); |
128 | | -// |
129 | | -// //Create DEF Semantic |
130 | | -// Semantic def = Semantic.make(PublicIds.newRandom()); |
131 | | -// activeSession.compose(new Definition() |
132 | | -// .semantic(def) |
133 | | -// .language(TinkarTermV2.ENGLISH_LANGUAGE) |
134 | | -// .text(data.def().isEmpty() ? data.fqn() : data.def()) |
135 | | -// .caseSignificance(TinkarTermV2.DESCRIPTION_NOT_CASE_SENSITIVE), concept); |
136 | | -// semanticCounter.incrementAndGet(); |
137 | | -// activeSession.compose(new USDialect().acceptability(TinkarTermV2.PREFERRED), def); |
138 | | -// semanticCounter.incrementAndGet(); |
139 | | -// |
140 | | -// //Create Identifier Semantic |
141 | | -// if (!data.ids().isEmpty()) { |
142 | | -// activeSession.compose(new Identifier().source(EC_IDENTIFIER_CONCEPT).ids(data.ids()), concept); |
143 | | -// semanticCounter.incrementAndGet(); |
144 | | -// } |
145 | | -// } |
146 | | -// LOG.info("Finish transforming {} Viewable Data", viewableData.size()); |
147 | | - } |
148 | | - |
149 | | - public void navigableTransformation(List<NavigableExtract> navigableData) { |
150 | | - //Need Stated Relationship to tie to main hierarchy |
151 | | - activeSession.compose(new StatedAxiom().isA(ESH_MODEL_CONCEPT), Concept.make(PublicIds.of(UUID.fromString("47e533f4-a3d8-5d5b-826d-24eb09d1f3ab")))); |
152 | | - |
153 | | - for (NavigableExtract navData : navigableData) { |
154 | | - Concept reference = Concept.make(PublicIds.of(navData.childId())); |
155 | | - if (navData.parentId() == null) { |
156 | | - System.out.println("break"); |
157 | | - } |
158 | | - Concept parent = Concept.make(PublicIds.of(navData.parentId())); |
159 | | - activeSession.compose(new StatedAxiom().isA(parent), reference); |
160 | | - } |
| 149 | + navigableData.forEach(data -> { |
| 150 | + Concept reference = Concept.make(PublicIds.of(data.childId())); |
| 151 | + List<Concept> parentConcepts = data.parentIds().stream() |
| 152 | + .map(PublicIds::of) |
| 153 | + .map(Concept::make) |
| 154 | + .toList(); |
| 155 | + activeSession.compose(new StatedAxiom().isA(parentConcepts.toArray(new Concept[0])), reference); |
| 156 | + }); |
161 | 157 | LOG.info("Finish transforming {} Navigable Data", navigableData.size()); |
162 | 158 | } |
163 | 159 |
|
164 | 160 | @Override |
165 | | - public void close() throws Exception { |
| 161 | + public void close() { |
166 | 162 | composer.commitAllSessions(); |
167 | 163 | } |
168 | 164 | } |
0 commit comments