Skip to content

Commit

Permalink
Improve naming of MetaKB and MockedKnowledgeBase
Browse files Browse the repository at this point in the history
  • Loading branch information
bnouwt committed Dec 20, 2024
1 parent 0e9a356 commit 636132c
Show file tree
Hide file tree
Showing 46 changed files with 280 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Knowledge Bases within the network and also provides REST APIs to access the
* same information including relations between knowledge bases.
*/
public class AdminUI extends MetaKB {
public class AdminUI extends MetadataKB {

private static final Logger LOG = LoggerFactory.getLogger(AdminUI.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import eu.knowledge.engine.smartconnector.api.ReactExchangeInfo;
import eu.knowledge.engine.smartconnector.api.ReactKnowledgeInteraction;
import eu.knowledge.engine.smartconnector.api.Vocab;
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase;
import eu.knowledge.engine.smartconnector.util.EasyKnowledgeBase;

/**
* Knowledge Base that keeps track of all other KBs in the network. It does this
Expand All @@ -35,9 +35,9 @@
* interactions.
*
*/
public class MetaKB extends MockedKnowledgeBase {
public class MetadataKB extends EasyKnowledgeBase {

private static final Logger LOG = LoggerFactory.getLogger(MetaKB.class);
private static final Logger LOG = LoggerFactory.getLogger(MetadataKB.class);

private static final String META_GRAPH_PATTERN_STR = "?kb rdf:type ke:KnowledgeBase . ?kb ke:hasName ?name . ?kb ke:hasDescription ?description . ?kb ke:hasKnowledgeInteraction ?ki . ?ki rdf:type ?kiType . ?ki ke:isMeta ?isMeta . ?ki ke:hasCommunicativeAct ?act . ?act rdf:type ke:CommunicativeAct . ?act ke:hasRequirement ?req . ?act ke:hasSatisfaction ?sat . ?req rdf:type ?reqType . ?sat rdf:type ?satType . ?ki ke:hasGraphPattern ?gp . ?gp rdf:type ?patternType . ?gp ke:hasPattern ?pattern .";

Expand All @@ -62,7 +62,7 @@ public class MetaKB extends MockedKnowledgeBase {
* Intialize a AdminUI that regularly retrieves and prints metadata about the
* available knowledge bases.
*/
public MetaKB(String id, String name, String description) {
public MetadataKB(String id, String name, String description) {
super(id, name, description);
readyPhaser = new Phaser(0);
this.setPhaser(this.readyPhaser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.slf4j.LoggerFactory;

import eu.knowledge.engine.admin.AdminUI;
import eu.knowledge.engine.admin.MetaKB;
import eu.knowledge.engine.admin.MetadataKB;
import eu.knowledge.engine.admin.Util;
import eu.knowledge.engine.admin.model.AnswerKnowledgeInteraction;
import eu.knowledge.engine.admin.model.AskKnowledgeInteraction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import eu.knowledge.engine.admin.AdminUI;
import eu.knowledge.engine.admin.MetaKB;
import eu.knowledge.engine.admin.MetadataKB;
import eu.knowledge.engine.smartconnector.api.AnswerHandler;
import eu.knowledge.engine.smartconnector.api.AnswerKnowledgeInteraction;
import eu.knowledge.engine.smartconnector.api.AskKnowledgeInteraction;
Expand All @@ -40,15 +40,15 @@
import eu.knowledge.engine.smartconnector.api.CommunicativeAct;
import eu.knowledge.engine.smartconnector.api.GraphPattern;
import eu.knowledge.engine.smartconnector.api.SmartConnector;
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase;
import eu.knowledge.engine.smartconnector.util.EasyKnowledgeBase;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class TestApiRoutes {
private Thread thread;
private static final Logger LOG = LoggerFactory.getLogger(TestApiRoutes.class);

private static MockedKnowledgeBase kb1;
private static MockedKnowledgeBase kb2;
private static EasyKnowledgeBase kb1;
private static EasyKnowledgeBase kb2;

private static AdminUI admin;
private HttpClient httpClient;
Expand Down Expand Up @@ -253,7 +253,7 @@ public void startKbs() throws InterruptedException {
int wait = 2;
final CountDownLatch kb2ReceivedData = new CountDownLatch(1);

kb1 = new MockedKnowledgeBase("kb1") {
kb1 = new EasyKnowledgeBase("kb1") {
@Override
public void smartConnectorReady(SmartConnector aSC) {
LOG.info("smartConnector of {} ready.", this.name);
Expand All @@ -280,7 +280,7 @@ public void smartConnectorReady(SmartConnector aSC) {
// todo: ask/poll if ready instead of waiting
Thread.sleep(5000);
kb2 = null;
kb2 = new MockedKnowledgeBase("kb2") {
kb2 = new EasyKnowledgeBase("kb2") {
@Override
public void smartConnectorReady(SmartConnector aSC) {
LOG.info("smartConnector of {} ready.", this.name);
Expand All @@ -305,7 +305,7 @@ public void stopKbs() {
stopKb(kb2);
}

public void stopKb(MockedKnowledgeBase aKb) {
public void stopKb(EasyKnowledgeBase aKb) {
if (aKb != null) {
aKb.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
import eu.knowledge.engine.smartconnector.impl.SmartConnectorBuilder;
import eu.knowledge.engine.smartconnector.impl.Util;

public class MockedKnowledgeBase implements KnowledgeBase {
public class EasyKnowledgeBase implements KnowledgeBase {

private static final Logger LOG = LoggerFactory.getLogger(MockedKnowledgeBase.class);
private static final Logger LOG = LoggerFactory.getLogger(EasyKnowledgeBase.class);

private final Set<AskKnowledgeInteraction> registeredAskKIs;
private final Map<AnswerKnowledgeInteraction, AnswerHandler> registeredAnswerKIs;
Expand Down Expand Up @@ -86,11 +86,11 @@ public class MockedKnowledgeBase implements KnowledgeBase {
*/
private boolean isThreadSafe = false;

public MockedKnowledgeBase(String aName) {
public EasyKnowledgeBase(String aName) {
this(null, aName, null);
}

public MockedKnowledgeBase(String anId, String aName, String aDescription) {
public EasyKnowledgeBase(String anId, String aName, String aDescription) {

assert aName != null;

Expand Down Expand Up @@ -291,7 +291,7 @@ public Map<ReactKnowledgeInteraction, ReactHandler> getReactKnowledgeInteraction
}

public boolean isUpToDate(AskKnowledgeInteraction askKnowledgeInteraction,
Set<MockedKnowledgeBase> someKnowledgeBases) {
Set<EasyKnowledgeBase> someKnowledgeBases) {

boolean isUpToDate = true;

Expand All @@ -306,7 +306,7 @@ public boolean isUpToDate(AskKnowledgeInteraction askKnowledgeInteraction,
// m.write(System.out, "turtle");
// System.out.println("-----------------------");

for (MockedKnowledgeBase aKnowledgeBase : someKnowledgeBases) {
for (EasyKnowledgeBase aKnowledgeBase : someKnowledgeBases) {
if (!this.getKnowledgeBaseId().toString().equals(aKnowledgeBase.getKnowledgeBaseId().toString())) {
isUpToDate &= isKnowledgeBaseUpToDate(aKnowledgeBase, m);
}
Expand All @@ -320,7 +320,7 @@ public boolean isUpToDate(AskKnowledgeInteraction askKnowledgeInteraction,

}

private boolean isKnowledgeBaseUpToDate(MockedKnowledgeBase aMockedKB, Model aModel) {
private boolean isKnowledgeBaseUpToDate(EasyKnowledgeBase aMockedKB, Model aModel) {

boolean isSame = true;
Resource kb = ResourceFactory.createResource(aMockedKB.getKnowledgeBaseId().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class KnowledgeNetwork {
* ready, Phase 2 = everybody is aware of everybody.
*/
private Phaser readyPhaser;
private Set<MockedKnowledgeBase> knowledgeBases;
private Map<MockedKnowledgeBase, AskKnowledgeInteraction> knowledgeInteractionMetadata;
private Set<EasyKnowledgeBase> knowledgeBases;
private Map<EasyKnowledgeBase, AskKnowledgeInteraction> knowledgeInteractionMetadata;
private PrefixMapping prefixMapping;

public KnowledgeNetwork() {
Expand All @@ -43,7 +43,7 @@ public KnowledgeNetwork() {
this.prefixMapping.setNsPrefix("kb", Vocab.ONTO_URI);
}

public void addKB(MockedKnowledgeBase aKB) {
public void addKB(EasyKnowledgeBase aKB) {
aKB.setPhaser(this.readyPhaser);
knowledgeBases.add(aKB);
}
Expand All @@ -59,9 +59,9 @@ public void sync() {
*/
private void startAndWaitForReady() {

Set<MockedKnowledgeBase> justStartedKBs = new HashSet<>();
Set<EasyKnowledgeBase> justStartedKBs = new HashSet<>();

for (MockedKnowledgeBase kb : this.knowledgeBases) {
for (EasyKnowledgeBase kb : this.knowledgeBases) {
if (!kb.isStarted()) {
kb.start();
justStartedKBs.add(kb);
Expand All @@ -87,14 +87,14 @@ private void startAndWaitForReady() {
// @formatter:on
);

for (MockedKnowledgeBase kb : justStartedKBs) {
for (EasyKnowledgeBase kb : justStartedKBs) {
AskKnowledgeInteraction anAskKI = new AskKnowledgeInteraction(new CommunicativeAct(), gp, null, false, true,
false, MatchStrategy.ENTRY_LEVEL);
this.knowledgeInteractionMetadata.put(kb, anAskKI);
kb.register(anAskKI);
}

for (MockedKnowledgeBase kb : this.knowledgeBases) {
for (EasyKnowledgeBase kb : this.knowledgeBases) {
kb.syncKIs();
}
}
Expand All @@ -110,9 +110,9 @@ private void waitForUpToDate() {
count++;
LOG.info("Checking up to date knowledge bases.");
allUpToDate = true;
Map<MockedKnowledgeBase, Boolean> upToDate = new HashMap<>();
Map<EasyKnowledgeBase, Boolean> upToDate = new HashMap<>();
boolean kbUpToDate;
for (MockedKnowledgeBase kb : this.knowledgeBases) {
for (EasyKnowledgeBase kb : this.knowledgeBases) {
kbUpToDate = kb.isUpToDate(this.knowledgeInteractionMetadata.get(kb), this.knowledgeBases);
allUpToDate &= kbUpToDate;
upToDate.put(kb, kbUpToDate);
Expand All @@ -130,11 +130,11 @@ private void waitForUpToDate() {
LOG.info("Everyone is up to date after {} rounds!", count);
}

private String getUpToDateInfo(Map<MockedKnowledgeBase, Boolean> upToDate) {
private String getUpToDateInfo(Map<EasyKnowledgeBase, Boolean> upToDate) {
StringBuilder sb = new StringBuilder();

sb.append("(");
for (Map.Entry<MockedKnowledgeBase, Boolean> entry : upToDate.entrySet()) {
for (Map.Entry<EasyKnowledgeBase, Boolean> entry : upToDate.entrySet()) {
sb.append(entry.getKey().getKnowledgeBaseName()).append("=").append(entry.getValue());
sb.append(",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.slf4j.LoggerFactory;

import eu.knowledge.engine.smartconnector.util.KnowledgeNetwork;
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase;
import eu.knowledge.engine.smartconnector.util.EasyKnowledgeBase;

@Tag("Long")
public class AdditionForAudienceTest {
Expand Down Expand Up @@ -72,12 +72,12 @@ public BindingSet react(ReactKnowledgeInteraction anRKI, ReactExchangeInfo aReac
}
};

MockedKnowledgeBase kb1;
MockedKnowledgeBase kb10;
MockedKnowledgeBase kb100;
MockedKnowledgeBase kbSum;
MockedKnowledgeBase kbNum;
MockedKnowledgeBase kbRule;
EasyKnowledgeBase kb1;
EasyKnowledgeBase kb10;
EasyKnowledgeBase kb100;
EasyKnowledgeBase kbSum;
EasyKnowledgeBase kbNum;
EasyKnowledgeBase kbRule;
private AskKnowledgeInteraction askKI;
private static KnowledgeNetwork kn;

Expand All @@ -86,7 +86,7 @@ public void beforeAll() {
kn = new KnowledgeNetwork();

// kb1
kb1 = new MockedKnowledgeBase("kb1");
kb1 = new EasyKnowledgeBase("kb1");
kb1.setReasonerEnabled(true);
kn.addKB(kb1);

Expand All @@ -97,7 +97,7 @@ public void beforeAll() {
kb1.register(reactKI, new MyReactHandler(1));

// kb10
kb10 = new MockedKnowledgeBase("kb10");
kb10 = new EasyKnowledgeBase("kb10");
kb10.setReasonerEnabled(true);
kn.addKB(kb10);
reactKI = new ReactKnowledgeInteraction(new CommunicativeAct(), new GraphPattern(
Expand All @@ -106,7 +106,7 @@ public void beforeAll() {
"?e <http://example.org/hasOutcome> ?n3 . ?n3 <http://example.org/type> <http://example.org/Number> . ?n3 <http://example.org/hasDigit> ?d3 . ?d3 <http://example.org/hasPlace> \"2\" . ?d3 <http://example.org/hasActualDigit> ?ad3 . ?d3 <http://example.org/hasOverflow> ?o ."));
kb10.register(reactKI, new MyReactHandler(2));

kb100 = new MockedKnowledgeBase("kb100");
kb100 = new EasyKnowledgeBase("kb100");
kb100.setReasonerEnabled(true);
kn.addKB(kb100);
reactKI = new ReactKnowledgeInteraction(new CommunicativeAct(), new GraphPattern(
Expand All @@ -115,7 +115,7 @@ public void beforeAll() {
"?e <http://example.org/hasOutcome> ?n3 . ?n3 <http://example.org/type> <http://example.org/Number> . ?n3 <http://example.org/hasDigit> ?d3 . ?d3 <http://example.org/hasPlace> \"3\" . ?d3 <http://example.org/hasActualDigit> ?ad3 . ?d3 <http://example.org/hasOverflow> ?o ."));
kb100.register(reactKI, new MyReactHandler(3));

kbSum = new MockedKnowledgeBase("kbSum");
kbSum = new EasyKnowledgeBase("kbSum");
kbSum.setReasonerEnabled(true);
kn.addKB(kbSum);

Expand Down Expand Up @@ -187,7 +187,7 @@ public void beforeAll() {
return bs;
});

kbNum = new MockedKnowledgeBase("kbNum");
kbNum = new EasyKnowledgeBase("kbNum");
kbNum.setReasonerEnabled(true);
kn.addKB(kbNum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import eu.knowledge.engine.reasoner.Rule;
import eu.knowledge.engine.reasoner.api.TriplePattern;
import eu.knowledge.engine.smartconnector.util.KnowledgeNetwork;
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase;
import eu.knowledge.engine.smartconnector.util.EasyKnowledgeBase;

/**
* This test tries to illustrate <i>generalize if necessary</i>. We instantiate
Expand All @@ -36,10 +36,10 @@ public class GeneralizeIfNecessaryTest {
private static final Logger LOG = LoggerFactory.getLogger(GeneralizeIfNecessaryTest.class);

private static KnowledgeNetwork kn = new KnowledgeNetwork();
private MockedKnowledgeBase appKb = new MockedKnowledgeBase("AppKB");
private MockedKnowledgeBase sensor1Kb = new MockedKnowledgeBase("Sensor1KB");
private MockedKnowledgeBase sensor2Kb = new MockedKnowledgeBase("Sensor2KB");
private MockedKnowledgeBase floorplanKb = new MockedKnowledgeBase("FloorplanKB");
private EasyKnowledgeBase appKb = new EasyKnowledgeBase("AppKB");
private EasyKnowledgeBase sensor1Kb = new EasyKnowledgeBase("Sensor1KB");
private EasyKnowledgeBase sensor2Kb = new EasyKnowledgeBase("Sensor2KB");
private EasyKnowledgeBase floorplanKb = new EasyKnowledgeBase("FloorplanKB");
private PrefixMapping prefixes = new PrefixMappingMem().setNsPrefix("ex", "http://example.org/").setNsPrefix("rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.slf4j.LoggerFactory;

import eu.knowledge.engine.smartconnector.util.KnowledgeNetwork;
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase;
import eu.knowledge.engine.smartconnector.util.EasyKnowledgeBase;

/**
* This test tries to balance the number of threads posting to a single KB to
Expand Down Expand Up @@ -82,8 +82,8 @@ public void run() {
private Queue<MessageTime> timings = new ConcurrentLinkedQueue<MessageTime>();

private KnowledgeNetwork kn = null;
private MockedKnowledgeBase poster = null;
private MockedKnowledgeBase reacter = null;
private EasyKnowledgeBase poster = null;
private EasyKnowledgeBase reacter = null;
private PostKnowledgeInteraction postKI = null;
private ReactKnowledgeInteraction reactKI = null;

Expand Down Expand Up @@ -151,10 +151,10 @@ public void run() {
public void test() throws InterruptedException {

kn = new KnowledgeNetwork();
poster = new MockedKnowledgeBase("poster");
poster = new EasyKnowledgeBase("poster");
poster.setIsThreadSafe(true);
kn.addKB(poster);
reacter = new MockedKnowledgeBase("reacter");
reacter = new EasyKnowledgeBase("reacter");
reacter.setIsThreadSafe(true);
kn.addKB(reacter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import eu.knowledge.engine.reasoner.Rule;
import eu.knowledge.engine.reasoner.api.TriplePattern;
import eu.knowledge.engine.smartconnector.util.KnowledgeNetwork;
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase;
import eu.knowledge.engine.smartconnector.util.EasyKnowledgeBase;

/**
* This test tries to illustrate <i>forward compatibility</i>. We instantiate an
Expand All @@ -37,9 +37,9 @@ public class NotDesignedToWorkTogetherTest {
private static final Logger LOG = LoggerFactory.getLogger(NotDesignedToWorkTogetherTest.class);

private static KnowledgeNetwork kn = new KnowledgeNetwork();
private MockedKnowledgeBase appKb = new MockedKnowledgeBase("AppKB");
private MockedKnowledgeBase lamp1Kb = new MockedKnowledgeBase("Lamp1KB");
private MockedKnowledgeBase lamp2Kb = new MockedKnowledgeBase("Lamp2KB");
private EasyKnowledgeBase appKb = new EasyKnowledgeBase("AppKB");
private EasyKnowledgeBase lamp1Kb = new EasyKnowledgeBase("Lamp1KB");
private EasyKnowledgeBase lamp2Kb = new EasyKnowledgeBase("Lamp2KB");
private PrefixMapping prefixes = new PrefixMappingMem().setNsPrefix("ex", "http://example.org/")
.setNsPrefix("time", "https://www.w3.org/TR/owl-time/")
.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Expand Down
Loading

0 comments on commit 636132c

Please sign in to comment.