1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/*-----------------------------------------------------------------------
File : cle_kbinsert.c
Author: Stephan Schulz
Contents
Copyright 1998, 1999 by the author.
This code is released under the GNU General Public Licence and
the GNU Lesser General Public License.
See the file COPYING in the main E directory for details..
Run "eprover -h" for contact information.
Changes
<1> Tue Jul 27 22:51:29 GMT 1999
New
-----------------------------------------------------------------------*/
#include "cle_kbinsert.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: ParseExampleClause()
//
// Parse an example clause into an annotated term format. Return
// clause as AnnoTerm or NULL if pattern-computation is to
// expensive.
//
// Global Variables: -
//
// Side Effects : Reads input
//
/----------------------------------------------------------------------*/
AnnoTerm_p ParseExampleClause(Scanner_p in, TB_p parse_terms, TB_p
internal_terms, long ident)
{
Term_p clauserep, newrep, tmp;
Clause_p clause;
Annotation_p anno = AnnotationAlloc();
long i;
double value;
PatternSubst_p subst;
PStack_p listrep;
AnnoTerm_p handle = NULL;
AcceptInpTok(in,PosInt);
AcceptInpTok(in,Colon);
anno->key = ident;
AcceptInpTok(in, OpenBracket);
/* The 0th position of the annotation vector always has the number
of original annotations merged into it -> as the annotation is
newly created, it's always 1 here. */
AnnotationCount(anno) = 1;
/* The first value is special! -> In the annotation, it is used
twice: For the number of proofs in which the clause was used
(position 1) and, as in the example
file, as the distance from the proof (position 2). */
if(AktToken(in)->numval == 0)
{
DDArrayAssign(anno->val1.p_val, 1, 1);
}
else
{
DDArrayAssign(anno->val1.p_val, 1, 0);
}
DDArrayAssign(anno->val1.p_val, 2, (float)AktToken(in)->numval);
AcceptInpTok(in, PosInt);
i=3;
while(TestInpTok(in, Comma))
{
AcceptInpTok(in, Comma);
value = ParseFloat(in);
DDArrayAssign(anno->val1.p_val, i, value);
i++;
}
anno->val2.i_val = i;
AcceptInpTok(in, CloseBracket);
AcceptInpTok(in, Colon);
clause = ClauseParse(in, parse_terms);
subst = PatternDefaultSubstAlloc(parse_terms->sig);
listrep = PStackAlloc();
if(PatternClauseCompute(clause, &subst, &listrep))
{
clauserep = RecEncodeClauseListRep(parse_terms, listrep);
tmp = PatternTranslateSig(clauserep, subst, parse_terms->sig,
internal_terms->sig,
internal_terms->vars);
newrep = TBInsert(internal_terms, tmp, DEREF_NEVER);
TermFree(tmp);
/* TBDelete(parse_terms, clauserep); */
handle = AnnoTermAlloc(newrep, anno);
}
else
{
AnnotationFree(anno);
}
ClauseFree(clause);
PatternSubstFree(subst);
PStackFree(listrep);
return handle;
}
/*-----------------------------------------------------------------------
//
// Function: KBAxiomsInsert()
//
// Insert the example "name" into set and return the ident
// assigned.
//
// Global Variables: -
//
// Side Effects : Changes set, memory operations
//
/----------------------------------------------------------------------*/
long KBAxiomsInsert(ExampleSet_p set, ClauseSet_p axioms, Sig_p sig,
char* name)
{
ExampleRep_p handle = ExampleRepCellAlloc();
handle->ident = set->count+1;
handle->name = SecureStrdup(name);
handle->features = FeaturesAlloc();
ComputeClauseSetNumFeatures(handle->features, axioms, sig);
ExampleSetInsert(set, handle);
return handle->ident;
}
/*-----------------------------------------------------------------------
//
// Function: KBParseExampleFile()
//
// Parse an example file into the existing structures.
//
// Global Variables: -
//
// Side Effects : Changes everything ;-)
//
/----------------------------------------------------------------------*/
void KBParseExampleFile(Scanner_p in, char* name, ExampleSet_p set,
AnnoSet_p examples, Sig_p res_sig)
{
TB_p terms;
ClauseSet_p axioms = ClauseSetAlloc();
long ident;
AnnoTerm_p handle;
TypeBank_p sort_table = TypeBankAlloc();
terms = TBAlloc(SigAlloc(sort_table));
ClauseSetParseList(in, axioms, terms);
ident = KBAxiomsInsert(set, axioms, terms->sig, name);
ClauseSetFree(axioms);
SigFree(terms->sig);
terms->sig = NULL;
TBFree(terms);
AcceptInpTok(in, Fullstop);
terms = TBAlloc(res_sig);
while(!TestInpTok(in, NoToken))
{
handle = ParseExampleClause(in, terms, examples->terms, ident);
if(handle)
{
AnnoSetAddTerm(examples, handle);
}
}
terms->sig = NULL;
TBFree(terms);
TypeBankFree(sort_table);
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|