1

tuprolog をダウンロードしましたが、次のクエリの結果を取得できませんでしたが、PROL ide で回答が得られました。誰か助けてもらえますか?

verb(admit-1).
verb(work-4).
nsubjpass(admit-1, patient-2).
agent(admit-1, doctor-3).
nsubj(work-4, who-5).
aux(work-4, be-6).
rcmod(doctor-3, work-4).
prep_in(work-4, clinic-7).


aggregation('part of').
aggregation('belongs to').
aggregation('subdivision of').
aggregation('have').
aggregation('contain').
aggregation('comprise').
aggregation('include').
aggregation('define').
aggregation('consist of').
aggregation('compose of').
aggregation('denote by').
aggregation('identify by').
aggregation('make up of').
aggregation('record with').

attribute('have').
attribute('contain').
attribute('comprise').
attribute('include').
attribute('define').
attribute('consist of').
attribute('compose of').
attribute('denote by').
attribute('identify by').
attribute('make up of').
attribute('record with').

generalization('be').
generalization('kind of').
generalization('type of').
generalization('classify into').
generalization('consider').

object(X) :- noun(X).
relation(X) :-  verb(X).
rel(X,Y) :- nsubjpass(X,Y).
rel(X,Y) :- agent(X,Y).
rel(X,Y) :- nsubj(X,Y).
rel(X,Y) :- aux(X,Y).
rel(X,Y) :- rcmod(X,Y).
rel(X,Y) :- prep_in(X,Y).

associatedWith(X,Y) :- rel(X,Y).
associatedWith(X,Y,Z) :- verb(Y),associatedWith(X,Y), associatedWith(Y,Z).
associatedWith(X,Y,Z) :- verb(X),associatedWith(X,Y), associatedWith(X,Z).
rel_aggregation(X,Y,R):-rel(X,Y).aggregation(R).

?- associatedWith(X,Y,Z).

私はこれらの種類の関係を処理し、出力をJavaで再度処理する必要があります

プロローグとJavaを統合する方法を教えてください。

編集:コードを実装することにより、tuprologでこのエラーが発生します

このコードは、associatedWith(X,Y) に対して機能します。つまり、2 つの引数がありますが、関連付けられた 3 つの引数 (X、Y、Z) を指定すると機能しません。どうすればいいですか..この例外が発生するのを手伝ってください

java.lang.ClassCastException: alice.tuprolog.Var cannot be cast to alice.tuprolog.Struct
        at alice.tuprolog.lib.BasicLibrary.agent_2(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at alice.tuprolog.PrimitiveInfo.evalAsPredicate(Unknown Source)
        at alice.tuprolog.StateGoalEvaluation.doJob(Unknown Source)
        at alice.tuprolog.Engine.run(Unknown Source)
        at alice.tuprolog.EngineManager.solve(Unknown Source)
        at alice.tuprolog.Prolog.solve(Unknown Source)
        at javaapplication9.Main.main(Main.java:26)
Exception in thread "main" alice.tuprolog.NoSolutionException
        at alice.tuprolog.SolveInfo.getSolution(Unknown Source)
        at javaapplication9.Main.main(Main.java:28)
Java Result: 1
4

2 に答える 2

5

Java で処理する必要がある主な tuProlog オブジェクトは次のとおりですTheory。 Prolog プログラムを表すために使用できます。Prolog、それはクエリを依頼するインタープリターです。およびSolveInfo、インタープリターによって検出された各ソリューションのデータを含みます。

Prolog プログラム (つまり、最後の行を除いて投稿したすべてのコード) が という名前のファイルに含まれているとしますtheory.pl。大まかに言えば (つまり、モジュロ インポートと例外)、従う必要がある手順は次のようになります。

Prolog engine = new Prolog();
Theory theory = new Theory(new FileInputStream("theory.pl"));
engine.setTheory(theory);
SolveInfo solution = engine.solve("associatedWith(X, Y, Z).");
if (solution.isSuccess()) {
    System.out.println(solution.getTerm("X"));
    System.out.println(solution.getTerm("Y"));
    System.out.println(solution.getTerm("Z"));
}

クエリで複数の解が得られる可能性がある場合は、whileループを使用して で未解決の選択肢の存在をテストし、 でProlog.hasOpenAlternatives別の解を取得しますProlog.solveNext

docマニュアルの第 8 章 ( tuProlog ディストリビューションのサブディレクトリにある PDF ファイル) には、Java コードから Prolog を操作する際の複雑さが増す小さな例が多数含まれています (特にセクション 8.4 を参照してください)。

于 2010-09-18T10:49:38.157 に答える
3

agent/2 は tuProlog の組み込みの述語です。バージョンの名前を変更してみてください。

于 2010-09-18T14:41:04.703 に答える