Embed MINERVA in your Java programs:...
Move to
Next Prev
Up Top
See also
Invocation
Predicates
Directives
Arithmetic
Functions
Objects
Error Messages
File Names
main
Packages
Debugger
Internationalization
Gui Programming
MINERVA to Java Interface
Java to MINERVA Interface
Restrictions
IF Computer > MINERVA > Manual > Reference > Java to MINERVA Interface

Java to MINERVA Interface

Embed MINERVA in your Java programs:

See also the javadoc style documentation.

If you only want to extend MINERVA with some Java classes/methods, then we recommend to use the MINERVA Extender minervax. This tools also allows to generate a new main program, which shows how to activate MINERVA.

If you want to use the class Minerva as a kind of thread not in charge of user interaction, for example because you prefer to use a GUI written with some other tool, then you can instantiate the class Minerva directly, invoke and obtain results with its method execute.

At instantiation time take care to supply the needed parameters; see the minerva* scripts for examples. If you invoke MINERVA from an applet you must also supply the reference to the applet.

The class Minerva knows two constructors:

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

The former is for convenience, it simply calls Minerva(null,args). Use the second one for invokation from an applet.

Example:

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);
        ...
    }
    ...
}

The interface from Java to MINERVA knows the following classes. (Abstract methods of the superclasses are of course defined in the subclasses but are not again listed there.)

  • abstract class MinervaTerm
    Superclass of a MinervaTerm. The method typeOf returns the type of the 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
    Superclass for the representation of numbers
    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
    representation of an integer
    public class MinervaLong extends MinervaNumber {
    	public MinervaLong(long value);
    }
    	

  • class MinervaDouble
    representation of a real
    public class MinervaDouble extends MinervaNumber {
    	public MinervaDouble(double value);
    }
    	

  • class MinervaObject
    representation of any object that cannot be represented as a standard Minerva term
    public class MinervaObject extends MinervaNumber {
    	public MinervaObject(Object object);
    

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

  • class MinervaVariable
    representation of a variable.
    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
    Superclass for compound structures.
    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
    representation of compound terms (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
    representation of lists
    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(); }

The following desribes the invocation interface of MINERVA from Java. The methods execute expect objects of type MinervaTerm. The methods execute can return results to Java.

When execute is called successfully, all objects of type MinervaVariable are associated (setValue()) with the terms they are unified with at exit time of the call.

Example:

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"); } } }

read on...
MINERVA
ifcomputer logo
f
Expert Services on the Web
Language
English
Japanese
Server
USA
Japan
Site Access
Local Index
Local Contents
Site Contents
Site Index
Printer Friendly
For imode
For PDA
Search
document: http://www.ifcomputer.co.jp/MINERVA/Manual/Reference/JavaToMinervaInterface/home_en.html
published 2008/5/12 update 2002/3/20 (c) 1996-2006 IF Computer Japan
IF Computer 5-28-2 Sendagi, Bunkyo-ku Tel +81-3-5814-3352 info@ifcomputer.com
Customer Support Tokyo 113-0022 Japan   http://www.ifcomputer.com
scroll to top managed with ubiCMS