当前位置: 首页>>代码示例>>Java>>正文


Java Prolog.addTheory方法代码示例

本文整理汇总了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());
}
 
开发者ID:fkoehne,项目名称:archi-prolog-exporter,代码行数:19,代码来源:AbstractBaseTest.java

示例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();
}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:18,代码来源:PrologAgentMind.java

示例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;
}
 
开发者ID:SeanTater,项目名称:uncc2014watsonsim,代码行数:81,代码来源:SupportCandidateType.java

示例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));
		}
	}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:45,代码来源:TestPrologMobius.java

示例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;
	}
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:43,代码来源:TestPrologMobius.java

示例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;
	}
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:43,代码来源:TestPrologMobius.java


注:本文中的alice.tuprolog.Prolog.addTheory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。