isac-java/src/java/isac/util/Formalization.java
author Walther Neuper <walther.neuper@jku.at>
Fri, 26 Mar 2021 10:45:05 +0100
changeset 5239 b4e3883d7b66
parent 5229 6bf0e95981e3
permissions -rw-r--r--
reset mathematics-engine to Isabelle2015

note: for this version libisabelle was available,
which connects front-end (Java) and back-end (Isabelle/ML)
     1 /****************************************************************** 
     2  * Copyright (c) 2003, Mario Hochreiter, Student of 
     3  * Software Engineering at FH-Hagenberg, Austria. 
     4  * Project member of the isac team at the Institute for 
     5  * Software-Technologie, Graz University of Technology, Austria. 
     6  * 
     7  * Use is subject to license terms.
     8  ******************************************************************/
     9 
    10 package isac.util;
    11 
    12 import isac.bridge.xml.DataTypes; // from libisabelle-full.jar
    13 import edu.tum.cs.isabelle.api.XML; // from libisabelle-full.jar
    14 
    15 import java.io.Serializable;
    16 import java.util.ArrayList;
    17 import java.util.Iterator;
    18 
    19 /**
    20  * Every calculation in the isac system starts with a formalization that
    21  * characterizes the calculation. A formalization object can contain multiple
    22  * <code>Variant</code> objects because a calculation can be calculated in
    23  * different ways (using different methods to solve the calculation).
    24  * 
    25  * @author Mario Hochreiter
    26  * @version 0.1
    27  *  
    28  */
    29 public class Formalization implements Serializable {
    30 
    31     static final long serialVersionUID = 4539906901989017369L;
    32     
    33 	protected ArrayList<Variant> variants_;
    34 
    35     public Formalization() {
    36         variants_ = new ArrayList<Variant>();
    37     }
    38 
    39     public void addNewVariant(Variant v) {
    40         variants_.add(v);
    41     }
    42 
    43     public ArrayList<Variant> getVariants() {
    44     	return variants_;
    45     }
    46     
    47     public Iterator<?> iterator() {
    48         return new FormalizationIterator(this);
    49     }
    50 
    51     public String toString() {
    52         String content = "<FORMALIZATION>\n";
    53         for (int index = 0; index < variants_.size(); index++)
    54             content += variants_.get(index) + "\n";
    55         content += "</FORMALIZATION>\n";
    56         return content;
    57     }
    58 
    59     /**
    60      * Format the object in a way that the bridge can handle it
    61      * 
    62      * @return SML representation of this Formalization
    63      */
    64     public String toSMLString() {
    65         // Use this String for empty Formalization:
    66         // Calculation from scratch
    67 
    68         if (variants_.isEmpty())
    69             return "[([], (\"e_domID\", [\"e_pblID\"], [\"e_metID\"]))]";
    70         //FIXME.WN04 e_domID, etc. will disappear soon: empty formalization
    71         // would be "[([], (\"\", [], []))]"
    72         StringBuffer sb = new StringBuffer();
    73         int size = variants_.size();
    74         int i = 0;
    75         Variant v;
    76 
    77         sb.append("[");
    78         Iterator<Variant> it = variants_.iterator();
    79         while (it.hasNext()) {
    80             v = (Variant) it.next();
    81             sb.append("(");
    82             sb.append(v.toSMLString());
    83             sb.append(")");
    84             if (i < size - 1) {
    85                 sb.append(",");
    86             }
    87             i++;
    88         }
    89         sb.append("]");
    90         return sb.toString();
    91 
    92     }
    93 
    94    /**
    95    * Format the object in a way that libisabelle/PIDE can handle it
    96    * @return XML representation of this Formalization
    97    */
    98    public XML.Tree toXML() {
    99     	
   100     	DataTypes.xml_of_str("equality (x+1=(2::real))");
   101     	
   102         return null; //XML.Tree
   103     }
   104 }
   105 
   106 class FormalizationIterator implements Iterator<Object> {
   107 
   108     Iterator<?> it_;
   109 
   110     FormalizationIterator(Formalization f) {
   111         it_ = f.variants_.iterator();
   112     }
   113 
   114     public void remove() {
   115         it_.remove();
   116     }
   117 
   118     public boolean hasNext() {
   119         return it_.hasNext();
   120     }
   121 
   122     public Object next() {
   123         return it_.next();
   124     }
   125 }