イフコンピュータ > MINERVA > マニュアル > レファレンス > JavaからMINERVAへのインタフェース

JavaからMINERVAへのインタフェース

MINERVA
ifcomputer logo
f
Expert Services on the Web

MINERVAをあなたのJavaプログラムへ組み込む:

参考: the javadoc style documentatio n.

MINERVAをJavaクラス/メソッドによって拡張したい場合には、 MINERVA Extender minervax を使用することをお勧めします。 このプログラムにより、class Minervaの呼び出し方の仕様を示す新しいメイン プログラムを生成することもできます。

他のツールで書かれたGUIを使用し、ユーザ対話を行なわない一種のスレッド としてclass Minerva使用したい場合、直接Minervaを起動し、 execute により、呼出と結果を得ることができます。

起動時には、必要なパラメータを与えます(minerva*の 各スクリプトを例として参照して下さい)。Minervaをアプレットから呼び出す場 合、そのアプレットも与えます。

class Minervaは、2つのコンストラクターがあります。 

     public Minerva(String[] args)
     public Minerva(Applet applet, String[] args)
 

前者は、便宜的なもので、Minerva(null,args)を呼び出すだけです。 アプレットから呼び出す場合には、後者を使用して下さい。

例:

public class Test extends Applet {
      Minerva minerva = null;
      ...
      public void start() {
          String args = new String[2];
          args[0] = "-c";
          args[1] = "/minerva/minervagui.mca";
          minerva = new Minerva(this, args);
          ...
      }
      ...
  }

JavaからMINERVAへのインタフェースは以下のクラスを知っています。 (上位クラスの絶対的なメソッドは、もちろんサブクラスでも定義されていますので 再びリストされはしません。)

  • abstract class MinervaTerm
    MinervaTermの上位クラス。typeOfのメソッドは term(VARIABLE .. LIST)のタイプを返す。
    abstract class MinervaTerm {
    	public static final int VARIABLE = 0;
    	public static final int ATOM = 1;
    	public static final int LONG = 2;
    	public static final int DOUBLE = 3;
    	public static final int OBJECT = 4;
    	public static final int COMPOUND = 5;
    	public static final int LIST = 6;
    

    // returns the type of a term abstract public int typeOf();

    // returns the identic term where every variable is replaced // with its associated term. The term itself is not modified. public MinervaTerm resolve() {

    // equality of two terms abstract public boolean equals(Object other);

    // returns hashCode for the term abstract public int hashCode();

    // returns a textual representation of a String abstract String toString(); }

  • class MinervaAtom
    public class MinervaAtom extends MinervaTerm {
    	// create an atom of the name 'name'
    	public MinervaAtom(String name);
    

    // returns the string associated with the atom public String stringValue(); }

  • class MinervaNumber
    数字表現の上位クラス。
    public abstract class MinervaNumber extends MinervaTerm {
    	// returns the value as an integer
    	abstract long longValue();
    

    // returns the value as a real abstract double doubleValue(); }

  • class MinervaLong
    整数の表現
    public class MinervaLong extends MinervaNumber {
    	public MinervaLong(long value);
    }
    	

  • class MinervaDouble
    実数の表現
    public class MinervaDouble extends MinervaNumber {
    	public MinervaDouble(double value);
    }
    	

  • class MinervaObject
    標準的なMinerva項として表現できないオブジェクトの表現
    public class MinervaObject extends MinervaNumber {
    	public MinervaObject(Object object);
    

    // returns the Object associated with a term public Object objectValue(); }

  • class MinervaVariable
    変数の表現
    public class MinervaVariable extends MinervaNumber {
    	public MinervaVariable();
    

    // sets the term that the variable shall be associated with public void setValue(MinervaTerm term);

    // enquire for the term associated with the variable. // NOTE: the method returns null if there is no term associated public MinervaTerm getValue(); }

  • class MinervaStruct
    複合した複合項の上位クラス
    public abstract class MinervaStruct extends MinervaTerm {
    	// return functor
    	abstract String getFunctor();
    	// return arity
    	abstract int getArity();
    	// return the i-th argument (0 <= i < getArity())
    	abstract MinervaTerm getArg(int i);
    	// associate a term with the i-th argument
    	abstract void setArg(int i, MinervaTerm term);
    }
    	

  • class MinervaCompound
    複合項(except lists)の表現
    public class MinervaCompound extends MinervaStruct {
    	// create functor(args[0], ... args[args.length])
    	public MinervaCompound(String functor, MinervaTerm[] args);
    

    // create a compound term. All arguments are initialized to null. // I.e. YOU HAVE to initialize them with setArg() public MinervaCompound(String functor, int arity);

    // create a unary compound: functor(a1) public MinervaCompound(String functor, MinervaTerm a1); public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2); public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3); public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3, MinervaTerm a4); public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3, MinervaTerm a4, MinervaTerm a5); public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3, MinervaTerm a4, MinervaTerm a5, MinervaTerm a6); }

  • class MinervaList
    リストの表現
    public class MinervaList extends MinervaStruct {
    	// construct a list: [head|tail]
    	public MinervaList(MinervaTerm head, MinervaTerm tail);
    

    // construct a list. Head and Tail of the list are initialized with null // i.e. YOU HAVE to initialize with setArg(), setHead(), setTail() public MinervaList();

    // returns the head of a list public MinervaTerm getHead();

    // returns the tail of a list public MinervaTerm getTail();

    // sets the head of a list public void setHead(MinervaTerm term);

    // sets the tail of a list public void setTail(MinervaTerm term);

    // returns an enumerator for the list. // With the enumerator it is easy to operate on all elements // of a list (cf index of an array) public Enumeration getEnumeration(); }

以下に、JavaからMINERVAのインタフェースの呼びだしについて説明します。 executeのメソッドは、 MinervaTermタイプのオブジェクト を期待します。executeのメソッドはJavaに結果を返します。

executeの呼びだしが行なわれれば、 MinervaVariableのすべてのタイプのオブジェクトは、 この呼びだしの終了時に値をもたされます。(setValue())

例:

import com.ifcomputer.minerva.*;

public class Test {

private static MinervaTerm makeChar(char c) { return new MinervaAtom(String.valueOf(c)); }

private static MinervaTerm makeList(String s) { MinervaTerm list = new MinervaAtom("[]"); for ( int i = s.length()-1; i >= 0; --i ) list = new MinervaList(makeChar(s.charAt(i)), list); return list; }

public static void main(String args[]) throws Exception { Minerva minerva = new Minerva(args); MinervaVariable v = new MinervaVariable(); MinervaTerm l1 = makeList("abc"); MinervaTerm l2 = makeList("def"); if ( minerva.execute("append", l1, l2, v) ) { System.out.println("append("+l1+", "+l2+") = "+v.getValue()); } else { System.out.println("execution failed"); } } }

document: http://www.ifcomputer.co.jp/MINERVA/Manual/Reference/JavaToMinervaInterface/print_jp.html
published 2008/9/1 update 2002/3/20 (c) 1996-2006 IF Computer Japan
IF Computer 〒113-0022 Tel 03-5814-3352 start (AT) ifcomputer.com
Customer Support 東京都文京区千駄木5-28-2   http://www.ifcomputer.co.jp
戻る> managed with ubiCMS