本文整理汇总了Java中alice.tuprolog.Prolog.addTheory方法的典型用法代码示例。如果您正苦于以下问题:Java Prolog.addTheory方法的具体用法?Java Prolog.addTheory怎么用?Java Prolog.addTheory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alice.tuprolog.Prolog
的用法示例。
在下文中一共展示了Prolog.addTheory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import alice.tuprolog.Prolog; //导入方法依赖的package包/类
@Before
public void setup() throws FileNotFoundException, IOException, InvalidTheoryException {
// Create a dummy model
model = ArchimateFactory.init().createArchimateModel();
modelUtil = new ModelUtil(model);
modelUtil.createElement(IArchimatePackage.eINSTANCE.getApplicationComponent(), "A", "a");
// Set up the engine with the predicates under test
engine = new Prolog();
Theory vocTheory = new Theory(new FileInputStream("prolog/vocabulary.pl"));
Theory consistencyTheory = new Theory(new FileInputStream("prolog/consistency.pl"));
engine.addTheory(vocTheory);
engine.addTheory(consistencyTheory);
// We will need the exporter to create .pl-Files of the dummy model but don't do that
// yet, in order to allow individual tests to modify the model before exporting.
exporter = new PrologExporter(new MockFileChooser());
}
示例2: PrologAgentMind
import alice.tuprolog.Prolog; //导入方法依赖的package包/类
/**
* Create a mind with a custom Prolog theory
*
* @param theory
*/
public PrologAgentMind(String theory){
Log.i(TAG, "Theory loaded:\n" + theory);
try {
prolog = new Prolog();
prolog.addTheory(new Theory(theory));
} catch (InvalidTheoryException ex) {
Log.e(TAG, "Prolog theory is not valid: " + ex.getMessage());
}
startPrologOutput();
}
示例3: extract
import alice.tuprolog.Prolog; //导入方法依赖的package包/类
/**
* Find simple statements of type in regular text, such as "Diabetes is a
* common disease"
*
* Subclasses are very similarly stated, such as "A hummingbird is a kind
* of bird." But we don't distinguish between these yet. We should though.
*
* @return Pairs of nouns and their types.
*/
public static List<Pair<String, String>> extract(Phrase p) {
List<Pair<String, String>> names_and_types = new ArrayList<>();
for (SemanticGraph graph: p.getGraphs()){
StringBuilder theory = new StringBuilder();
// Load data into a model
// Add all the edges
for (SemanticGraphEdge edge : graph.edgeIterable()) {
// I like the specific prepositions better
// so change them to match
GrammaticalRelation rel = edge.getRelation();
String relation_name = rel.getShortName();
if ( (rel.getShortName().equals("prep")
|| rel.getShortName().equals("conj"))
&& rel.getSpecific() != null
&& !rel.getSpecific().isEmpty()) {
relation_name = rel.getShortName() + "_" + CharSetUtils.keep(rel.getSpecific().toLowerCase(), "abcdefghijklmnopqrstuvwxyz");
}
theory.append(relation_name);
theory.append('(');
theory.append(wordID(edge.getGovernor()));
theory.append(',');
theory.append(wordID(edge.getDependent()));
theory.append(").\n");
}
// Index the words
for (IndexedWord word : graph.vertexSet()) {
theory.append("tag(");
theory.append(wordID(word));
theory.append(',');
String tag = clean(word.tag());
theory.append(tag.isEmpty() ? "misc" : tag);
theory.append(").\n");
}
Prolog engine = new Prolog();
try {
engine.setTheory(new Theory(
Files.toString(new File("src/main/parse.pl"), Charset.forName("UTF-8"))));
log.debug(theory);
engine.addTheory(new Theory(theory.toString()));
SolveInfo info = engine.solve("type_c(X, Y).");
// Get the resulting matches
while (info.isSuccess()) {
IndexedWord subj_idx = idWord(graph, info.getTerm("X").toString());
IndexedWord obj_idx = idWord(graph, info.getTerm("Y").toString());
if (subj_idx.tag().startsWith("NN")
&& obj_idx.tag().startsWith("NN")) {
String noun = Trees.concatNoun(graph, subj_idx);
String type = obj_idx.originalText(); //concatNoun(graph, obj_idx);
log.info("Discovered " + noun + " is a(n) " + type);
names_and_types.add(new Pair<>(noun,type));
}
if (engine.hasOpenAlternatives()) {
info = engine.solveNext();
} else {
break;
}
}
} catch (IOException | InvalidTheoryException
| MalformedGoalException | NoSolutionException
| NoMoreSolutionException | UnknownVarException e) {
System.out.println(theory);
e.printStackTrace();
}
}
return names_and_types;
}
示例4: test
import alice.tuprolog.Prolog; //导入方法依赖的package包/类
@Test
public void test() throws InvalidTheoryException, FileNotFoundException, IOException, MalformedGoalException, NoSolutionException, NoMoreSolutionException {
String kbfolder = "E:/sadl/workspace-sadl/Mobius2.new/OwlModels/";
String rdffile = "rdf.pl";
String stddecls = "tuprolog-custom-predicates.pl";
String entry = "PlanRecloserInstance.pl";
Prolog engine = new Prolog();
engine.clearTheory();
String fn = kbfolder + stddecls;
System.out.println("Loading " + fn);
engine.addTheory(createTheory(fn));
fn = kbfolder + entry;
System.out.println("Loading " + fn);
engine.addTheory(createTheory(fn));
fn = kbfolder + rdffile;
System.out.println("Loading " + fn);
engine.addTheory(createTheory(fn));
SolveInfo result = engine.solve("minSkillProficiency('http://www.mobius.illinois.edu/advise/ont/core/Attack#AdminModifyFWOpen',Sk,P).");
// SolveInfo result = engine.solve("preconditions(X,Y,Z).");
// SolveInfo result = engine.solve("holds(X,Y,Z).");
System.out.println(result.toString());
assertNotNull(result);
assertNotNull(result.getSolution());
int solution_count = 0;
List<String> solution_list = new ArrayList<String>();
while (result.isSuccess()) {
solution_count += 1;
List<Var> vars = result.getBindingVars();
StringBuilder sb = new StringBuilder();
for (Var var: vars){
sb.append(var.getName());
sb.append(": ");
sb.append(result.getVarValue(var.getName()).toString());
}
solution_list.add(sb.toString());
if (engine.hasOpenAlternatives())
result = engine.solveNext();
else
break;
}
for (int i = 0; i < solution_list.size(); i++) {
System.out.println("Solution " + i + ": " + solution_list.get(i));
}
}
示例5: test2
import alice.tuprolog.Prolog; //导入方法依赖的package包/类
@Test
public void test2() throws InvalidTheoryException, FileNotFoundException, IOException, MalformedGoalException, NoSolutionException, NoMoreSolutionException {
String kbfolder = "E:/sadl/workspace-sadl/Mobius2.new/OwlModels";
Prolog engine = new Prolog();
engine.clearTheory();
File plFilesFolder = new File(kbfolder);
File[] files = plFilesFolder.listFiles();
// first load prolog files and then owl/rdf files
for (int i = 0; i < files.length; i++){
String fn = files[i].getName();
if (fn.endsWith(".pl") &&
(fn.startsWith("PlanR") || fn.startsWith("plann") || fn.startsWith("pr") || fn.startsWith("r") || fn.startsWith("b"))) {
System.out.println("Loading " + files[i].getAbsolutePath());
try {
engine.addTheory(createTheory(files[i].getAbsolutePath()));
} catch (InvalidTheoryException e) {
// TODO Auto-generated catch block
System.err.println("Syntax error: " + e.getMessage());
}
}
}
SolveInfo result = engine.solve("minSkillProficiency('http://www.mobius.illinois.edu/advise/ont/core/Attack#AdminModifyFWOpen',Sk,P).");
System.out.println(result.toString());
assertNotNull(result);
assertNotNull(result.getSolution());
int solution_count = 0;
List<String> solution_list = new ArrayList<String>();
while (result.isSuccess()) {
solution_count += 1;
List<Var> vars = result.getBindingVars();
for (Var var: vars){
solution_list.add(result.getVarValue(var.getName()).toString());
}
//System.out.println(solution.getBindingVars());
//System.out.println(solution.getSolution().toString());
if (engine.hasOpenAlternatives())
result = engine.solveNext();
else
break;
}
}
示例6: test3
import alice.tuprolog.Prolog; //导入方法依赖的package包/类
@Test
public void test3() throws InvalidTheoryException, FileNotFoundException, IOException, MalformedGoalException, NoSolutionException, NoMoreSolutionException {
String kbfolder = "E:/sadl/workspace-sadl/Mobius2.new/OwlModels";
Prolog engine = new Prolog();
engine.clearTheory();
File plFilesFolder = new File(kbfolder);
File[] files = plFilesFolder.listFiles();
// first load prolog files and then owl/rdf files
for (int i = 0; i < files.length; i++){
String fn = files[i].getName();
if (fn.endsWith(".pl") &&
(fn.startsWith("PlanR") || fn.startsWith("plann") || fn.startsWith("pr") || fn.startsWith("r") || fn.startsWith("b"))) {
System.out.println("Loading " + files[i].getAbsolutePath());
try {
engine.addTheory(createTheory(files[i].getAbsolutePath()));
} catch (InvalidTheoryException e) {
// TODO Auto-generated catch block
System.err.println("Syntax error: " + e.getMessage());
}
}
}
SolveInfo result = engine.solve("preconditions(X,Y,Z).");
System.out.println(result.toString());
assertNotNull(result);
assertNotNull(result.getSolution());
int solution_count = 0;
List<String> solution_list = new ArrayList<String>();
while (result.isSuccess()) {
solution_count += 1;
List<Var> vars = result.getBindingVars();
for (Var var: vars){
solution_list.add(result.getVarValue(var.getName()).toString());
}
//System.out.println(solution.getBindingVars());
//System.out.println(solution.getSolution().toString());
if (engine.hasOpenAlternatives())
result = engine.solveNext();
else
break;
}
}