-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAdminUI.java
More file actions
134 lines (103 loc) · 4.08 KB
/
AdminUI.java
File metadata and controls
134 lines (103 loc) · 4.08 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package eu.knowledge.engine.admin;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Phaser;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.knowledge.engine.smartconnector.api.BindingSet;
import eu.knowledge.engine.smartconnector.api.ReactExchangeInfo;
/**
* Knowledge Base that regularly prints an overview of the currently available
* Knowledge Bases within the network and also provides REST APIs to access the
* same information including relations between knowledge bases.
*/
public class AdminUI extends MetadataKB {
private static final Logger LOG = LoggerFactory.getLogger(AdminUI.class);
private static AdminUI instance;
private static boolean continuousLog = true;
private static String knowledgeBaseId = "https://knowledge-engine.eu/adminui-" + UUID.randomUUID();
private static String knowledgeBaseName = "Admin UI";
private static String knowledgeBaseDescription = "Publishes an overview of all the available Knowledge Bases via a REST API.";
private AdminUI() {
super(knowledgeBaseId, knowledgeBaseName, knowledgeBaseDescription);
}
public static AdminUI newInstance(boolean useLog) {
if (instance == null) {
continuousLog = useLog;
instance = new AdminUI();
}
instance.setPhaser(new Phaser(1));
instance.start();
instance.syncKIs();
return instance;
}
@Override
public BindingSet handleNewKnowledgeBase(ReactExchangeInfo ei) {
BindingSet bs = super.handleNewKnowledgeBase(ei);
// when result available (and the config is enabled), we print the
// knowledge bases to the console.
this.printKnowledgeBases(this.getMetadata());
return bs;
}
@Override
public BindingSet handleChangedKnowledgeBase(ReactExchangeInfo ei) {
BindingSet bs = super.handleChangedKnowledgeBase(ei);
// when result available (and the config is enabled), we print the
// knowledge bases to the console.
this.printKnowledgeBases(this.getMetadata());
return bs;
}
@Override
public BindingSet handleRemovedKnowledgeBase(ReactExchangeInfo ei) {
BindingSet bs = super.handleRemovedKnowledgeBase(ei);
// when result available (and the config is enabled), we print the
// knowledge bases to the console.
this.printKnowledgeBases(this.getMetadata());
return bs;
}
@Override
public void fetchInitialData() {
super.fetchInitialData();
// when result available (and the config is enabled), we print the
// knowledge bases to the console.
this.printKnowledgeBases(this.getMetadata());
}
private void printKnowledgeBases(Model model) {
if (continuousLog) {
// LOG.info("{}", this.getRDF(model));
LOG.info("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
LOG.info("-=-=-=-=-=-=-= Admin UI -=-=-=-=-=-=-=-");
LOG.info("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
if (!model.isEmpty()) {
Set<Resource> kbs = Util.getKnowledgeBaseURIs(model);
int i = 0;
for (Resource kbRes : kbs) {
i++;
if (i > 1) {
LOG.info("");
}
LOG.info("Knowledge Base <{}>", kbRes);
LOG.info("\t* Name: {}", Util.getName(model, kbRes));
LOG.info("\t* Description: {}", Util.getDescription(model, kbRes));
Set<Resource> kiResources = Util.getKnowledgeInteractionURIs(model, kbRes);
for (Resource kiRes : kiResources) {
String knowledgeInteractionType = Util.getKnowledgeInteractionType(model, kiRes);
LOG.info("\t* {}{}", knowledgeInteractionType, (Util.isMeta(model, kiRes) ? " (meta)" : ""));
if (knowledgeInteractionType.equals("AskKnowledgeInteraction")
|| knowledgeInteractionType.equals("AnswerKnowledgeInteraction")) {
LOG.info("\t\t- GraphPattern: {}", Util.getGraphPattern(model, kiRes));
} else if (knowledgeInteractionType.equals("PostKnowledgeInteraction")
|| knowledgeInteractionType.equals("ReactKnowledgeInteraction")) {
LOG.info("\t\t- Argument GP: {}", Util.getArgument(model, kiRes));
LOG.info("\t\t- Result GP: {}", Util.getResult(model, kiRes));
}
}
}
} else {
LOG.info("No other knowledge bases found.");
}
}
}
}