diff --git a/admin-ui/src/main/java/eu/knowledge/engine/admin/MetadataKB.java b/admin-ui/src/main/java/eu/knowledge/engine/admin/MetadataKB.java index 5dcb412a7..af5ede19d 100644 --- a/admin-ui/src/main/java/eu/knowledge/engine/admin/MetadataKB.java +++ b/admin-ui/src/main/java/eu/knowledge/engine/admin/MetadataKB.java @@ -74,20 +74,20 @@ public MetadataKB(String id, String name, String description) { this.metaGraphPattern = new GraphPattern(this.prefixes, META_GRAPH_PATTERN_STR); // create the correct Knowledge Interactions - this.aKI = new AskKnowledgeInteraction(new CommunicativeAct(), this.metaGraphPattern, null, false, true, - false, MatchStrategy.ENTRY_LEVEL); + this.aKI = new AskKnowledgeInteraction(new CommunicativeAct(), this.metaGraphPattern, "ask-metadata", false, + true, false, MatchStrategy.ENTRY_LEVEL); this.rKINew = new ReactKnowledgeInteraction( new CommunicativeAct(new HashSet(Arrays.asList(Vocab.NEW_KNOWLEDGE_PURPOSE)), new HashSet(Arrays.asList(Vocab.INFORM_PURPOSE))), - this.metaGraphPattern, null); + this.metaGraphPattern, null, "react-to-new-metadata"); this.rKIChanged = new ReactKnowledgeInteraction( new CommunicativeAct(new HashSet(Arrays.asList(Vocab.CHANGED_KNOWLEDGE_PURPOSE)), new HashSet(Arrays.asList(Vocab.INFORM_PURPOSE))), - this.metaGraphPattern, null); + this.metaGraphPattern, null, "react-to-changed-metadata"); this.rKIRemoved = new ReactKnowledgeInteraction( new CommunicativeAct(new HashSet(Arrays.asList(Vocab.REMOVED_KNOWLEDGE_PURPOSE)), new HashSet(Arrays.asList(Vocab.INFORM_PURPOSE))), - this.metaGraphPattern, null); + this.metaGraphPattern, null, "react-to-removed-metadata"); // register the knowledge interactions with the smart connector. this.register(this.aKI); diff --git a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/MetaKnowledgeBaseImpl.java b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/MetaKnowledgeBaseImpl.java index 71c5b89e5..37f687fa1 100644 --- a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/MetaKnowledgeBaseImpl.java +++ b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/MetaKnowledgeBaseImpl.java @@ -95,32 +95,32 @@ public MetaKnowledgeBaseImpl(LoggerProvider loggerProvider, MessageRouter aMessa (anAKI, anAnswerExchangeInfo) -> this.fillMetaBindings(anAnswerExchangeInfo.getIncomingBindings()), true); - this.metaAskKI = new AskKnowledgeInteraction(new CommunicativeAct(), this.metaGraphPattern, null, true, true, false, - MatchStrategy.ENTRY_LEVEL); + this.metaAskKI = new AskKnowledgeInteraction(new CommunicativeAct(), this.metaGraphPattern, null, true, true, + false, MatchStrategy.ENTRY_LEVEL); this.knowledgeBaseStore.register(this.metaAskKI, true); this.metaPostNewKI = new PostKnowledgeInteraction( new CommunicativeAct(new HashSet<>(Arrays.asList(Vocab.INFORM_PURPOSE)), new HashSet<>(Arrays.asList(Vocab.NEW_KNOWLEDGE_PURPOSE))), - this.metaGraphPattern, null, null, true, true, MatchStrategy.ENTRY_LEVEL); + this.metaGraphPattern, null, "post-new", true, true, MatchStrategy.ENTRY_LEVEL); this.knowledgeBaseStore.register(this.metaPostNewKI, true); this.metaPostChangedKI = new PostKnowledgeInteraction( new CommunicativeAct(new HashSet<>(Arrays.asList(Vocab.INFORM_PURPOSE)), new HashSet<>(Arrays.asList(Vocab.CHANGED_KNOWLEDGE_PURPOSE))), - this.metaGraphPattern, null, null, true, true, MatchStrategy.ENTRY_LEVEL); + this.metaGraphPattern, null, "post-changed", true, true, MatchStrategy.ENTRY_LEVEL); this.knowledgeBaseStore.register(this.metaPostChangedKI, true); this.metaPostRemovedKI = new PostKnowledgeInteraction( new CommunicativeAct(new HashSet<>(Arrays.asList(Vocab.INFORM_PURPOSE)), new HashSet<>(Arrays.asList(Vocab.REMOVED_KNOWLEDGE_PURPOSE))), - this.metaGraphPattern, null, null, true, true, MatchStrategy.ENTRY_LEVEL); + this.metaGraphPattern, null, "post-removed", true, true, MatchStrategy.ENTRY_LEVEL); this.knowledgeBaseStore.register(this.metaPostRemovedKI, true); this.metaReactNewKI = new ReactKnowledgeInteraction( new CommunicativeAct(new HashSet<>(Arrays.asList(Vocab.NEW_KNOWLEDGE_PURPOSE)), new HashSet<>(Arrays.asList(Vocab.INFORM_PURPOSE))), - this.metaGraphPattern, null, null, true, true, MatchStrategy.ENTRY_LEVEL); + this.metaGraphPattern, null, "react-new", true, true, MatchStrategy.ENTRY_LEVEL); this.knowledgeBaseStore.register(this.metaReactNewKI, (aRKI, aReactExchangeInfo) -> { var postingKi = aReactExchangeInfo.getPostingKnowledgeInteractionId(); var itShouldBeThis = this.knowledgeBaseStore.getMetaId(aReactExchangeInfo.getPostingKnowledgeBaseId(), @@ -140,7 +140,7 @@ public MetaKnowledgeBaseImpl(LoggerProvider loggerProvider, MessageRouter aMessa this.metaReactChangedKI = new ReactKnowledgeInteraction( new CommunicativeAct(new HashSet<>(Arrays.asList(Vocab.CHANGED_KNOWLEDGE_PURPOSE)), new HashSet<>(Arrays.asList(Vocab.INFORM_PURPOSE))), - this.metaGraphPattern, null, null, true, true, MatchStrategy.ENTRY_LEVEL); + this.metaGraphPattern, null, "react-changed", true, true, MatchStrategy.ENTRY_LEVEL); this.knowledgeBaseStore.register(this.metaReactChangedKI, (aRKI, aReactExchangeInfo) -> { var postingKi = aReactExchangeInfo.getPostingKnowledgeInteractionId(); var itShouldBeThis = this.knowledgeBaseStore.getMetaId(aReactExchangeInfo.getPostingKnowledgeBaseId(), @@ -160,7 +160,7 @@ public MetaKnowledgeBaseImpl(LoggerProvider loggerProvider, MessageRouter aMessa this.metaReactRemovedKI = new ReactKnowledgeInteraction( new CommunicativeAct(new HashSet<>(Arrays.asList(Vocab.REMOVED_KNOWLEDGE_PURPOSE)), new HashSet<>(Arrays.asList(Vocab.INFORM_PURPOSE))), - this.metaGraphPattern, null, null, true, true, MatchStrategy.ENTRY_LEVEL); + this.metaGraphPattern, null, "react-removed", true, true, MatchStrategy.ENTRY_LEVEL); this.knowledgeBaseStore.register(this.metaReactRemovedKI, (aRKI, aReactExchangeInfo) -> { var postingKi = aReactExchangeInfo.getPostingKnowledgeInteractionId(); var itShouldBeThis = this.knowledgeBaseStore.getMetaId(aReactExchangeInfo.getPostingKnowledgeBaseId(), @@ -410,8 +410,8 @@ private OtherKnowledgeBase constructOtherKnowledgeBaseFromBindingSet(BindingSet var kiMeta = model.listObjectsOfProperty(ki, Vocab.IS_META).next(); boolean isMeta = kiMeta.asLiteral().getBoolean(); - assert isMeta == kiMeta.toString().contains("true") - : "If the text contains 'true' (=" + kiMeta + ") then the boolean should be true."; + assert isMeta == kiMeta.toString().contains("true") : "If the text contains 'true' (=" + kiMeta + + ") then the boolean should be true."; this.LOG.trace("meta: {} = {}", FmtUtils.stringForNode(kiMeta.asNode()), isMeta); diff --git a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/util/KnowledgeNetwork.java b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/util/KnowledgeNetwork.java index 699fbfdd4..9326f5e1a 100644 --- a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/util/KnowledgeNetwork.java +++ b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/util/KnowledgeNetwork.java @@ -19,6 +19,7 @@ import eu.knowledge.engine.smartconnector.api.GraphPattern; import eu.knowledge.engine.smartconnector.api.MatchStrategy; import eu.knowledge.engine.smartconnector.api.Vocab; +import eu.knowledge.engine.smartconnector.impl.SmartConnectorImpl; public class KnowledgeNetwork { @@ -77,7 +78,7 @@ private void startAndWaitForReady() { // register our state check Knowledge Interaction on each Smart Connecotr GraphPattern gp = new GraphPattern(this.prefixMapping, - // @formatter:off + // @formatter:off "?kb rdf:type kb:KnowledgeBase .", "?kb kb:hasName ?name .", "?kb kb:hasDescription ?description .", "?kb kb:hasKnowledgeInteraction ?ki .", "?ki rdf:type ?kiType .", "?ki kb:isMeta ?isMeta .", "?ki kb:hasCommunicativeAct ?act .", "?act rdf:type kb:CommunicativeAct .", @@ -156,4 +157,17 @@ public CompletableFuture stop() { this.knowledgeBases.clear(); return CompletableFuture.allOf(kbStoppedFutures.toArray(new CompletableFuture[kbStoppedFutures.size()])); } + + /** + * Removes the given KB from this network object, but does not stop it. + * + * It can be stopped manually using the {@link SmartConnectorImpl#stop()} + * method. + * + * @param aKb An existing knowledge base that should be removed. + */ + public void removeKB(KnowledgeBaseImpl aKb) { + this.knowledgeInteractionMetadata.remove(aKb); + this.knowledgeBases.remove(aKb); + } }