本文整理汇总了Java中alice.tuprolog.Theory类的典型用法代码示例。如果您正苦于以下问题:Java Theory类的具体用法?Java Theory怎么用?Java Theory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Theory类属于alice.tuprolog包,在下文中一共展示了Theory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setup
import alice.tuprolog.Theory; //导入依赖的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());
}
开发者ID:fkoehne,项目名称:archi-prolog-exporter,代码行数:19,代码来源:AbstractBaseTest.java
示例2: getTheory
import alice.tuprolog.Theory; //导入依赖的package包/类
public Theory getTheory(JavaLibrary javaLibrary, EvaluationContext evalCtx, Element elt) throws InvalidTheoryException {
List<Element> factElements = this.resolvedFacts.evaluateList(evalCtx, elt);
Struct[] facts = new Struct[factElements.size()];
for (int i = 0; i < facts.length; ++i) {
facts[i] = buildFact(javaLibrary, evalCtx, factElements.get(i));
}
return new Theory(new Struct(facts));
}
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:9,代码来源:FactDefinition.java
示例3: PrologAgentMind
import alice.tuprolog.Theory; //导入依赖的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();
}
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:18,代码来源:PrologAgentMind.java
示例4: InferenceMachine
import alice.tuprolog.Theory; //导入依赖的package包/类
/**
* Constructs the inference machine loading an existing knowledge base from "file"
*/
public InferenceMachine(File file) throws InvalidTheoryException, FileNotFoundException, IOException {
this();
Theory theory = new Theory(new FileInputStream(file));
inferenceMachine.addTheory(theory);
}
开发者ID:dew-uff,项目名称:expline,代码行数:11,代码来源:InferenceMachine.java
示例5: buildTheory
import alice.tuprolog.Theory; //导入依赖的package包/类
@TimeThis(task="load-program", category=TimerCategory.LOAD_RESOURCE)
protected Theory buildTheory(@SuppressWarnings("unused") ProcessingContext<Corpus> ctx) throws IOException {
try (InputStream is = theory.getInputStream()) {
return new Theory(is);
}
}
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:7,代码来源:RunProlog.java
示例6: extract
import alice.tuprolog.Theory; //导入依赖的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;
}
开发者ID:SeanTater,项目名称:uncc2014watsonsim,代码行数:81,代码来源:SupportCandidateType.java
示例7: createTheoryByConsult
import alice.tuprolog.Theory; //导入依赖的package包/类
public Theory createTheoryByConsult(String filename) throws InvalidTheoryException {
return new Theory(":- consult('" + filename + "').");
}
开发者ID:crapo,项目名称:sadlos2,代码行数:4,代码来源:OntologyInterface.java
示例8: createTheory
import alice.tuprolog.Theory; //导入依赖的package包/类
private Theory createTheory(String filename) throws InvalidTheoryException {
return new Theory(":- consult('" + filename + "').");
}
开发者ID:crapo,项目名称:sadlos2,代码行数:4,代码来源:TestPrologMobius.java
示例9: accessLevel
import alice.tuprolog.Theory; //导入依赖的package包/类
public synchronized String accessLevel(PassedContext passedContext) throws Exception
{
Struct passedContextTerm = new Struct("passedContext");
javaLibrary.register(passedContextTerm, passedContext);
Struct dateAndTimeTerm = new Struct("dateAndTime");
javaLibrary.register(dateAndTimeTerm, new DateAndTime());
if(!theoryLoaded)
{
logger.info("Loading access databases from "+libPath+" and "+accessPath);
FileInputStream libStream = null;
FileInputStream accessStream = null;
try
{
libStream = new FileInputStream(URLDecoder.decode(Prolog.class.getResource(libPath).getPath(),"UTF-8"));
accessStream = new FileInputStream(URLDecoder.decode(Prolog.class.getResource(accessPath).getPath(),"UTF-8"));
prolog.setTheory(new Theory(libStream));
prolog.addTheory(new Theory(accessStream));
}
finally
{
if(libStream != null)
{
libStream.close();
}
if(accessStream != null)
{
accessStream.close();
}
}
logger.info(String.valueOf(prolog.getTheory()));
theoryLoaded = true;
}
String highestLevel = "no";
if(prolog.solve(new Struct("canAccess",new Struct("readAccess"))).isSuccess())
{
highestLevel = "read";
}
if(prolog.solve(new Struct("canAccess",new Struct("writeAccess"))).isSuccess())
{
highestLevel = "write";
}
if(prolog.solve(new Struct("canAccess",new Struct("specialAccess"))).isSuccess())
{
highestLevel = "special";
}
if(highestLevel.equals("special") && prolog.solve(new Struct("cannotAccess",new Struct("specialAccess"))).isSuccess())
{
highestLevel = "write";
}
if(highestLevel.equals("write") && prolog.solve(new Struct("cannotAccess",new Struct("writeAccess"))).isSuccess())
{
highestLevel = "read";
}
if(highestLevel.equals("read") && prolog.solve(new Struct("cannotAccess",new Struct("readAccess"))).isSuccess())
{
highestLevel = "no";
}
javaLibrary.unregister(dateAndTimeTerm);
javaLibrary.unregister(passedContextTerm);
return highestLevel;
}
开发者ID:unoduetre,项目名称:ACoDIS,代码行数:69,代码来源:Prolog.java
示例10: load
import alice.tuprolog.Theory; //导入依赖的package包/类
/**
* Load a model into the prolog engine - here we assume that the MockFileChooser is in use.
*
* @throws InvalidTheoryException
* @throws IOException
* @throws FileNotFoundException
*/
protected void load() throws InvalidTheoryException, IOException, FileNotFoundException {
engine.addTheory(new Theory(exporter.getWriter().toString()));
}
开发者ID:fkoehne,项目名称:archi-prolog-exporter,代码行数:11,代码来源:AbstractBaseTest.java
注:本文中的alice.tuprolog.Theory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论