@@ -10,6 +10,7 @@ import lisa.utils.KernelHelpers.*
10
10
import lisa .utils .KernelHelpers .given_Conversion_Identifier_String
11
11
import lisa .utils .KernelHelpers .given_Conversion_String_Identifier
12
12
import lisa .utils .tptp .*
13
+ import lisa .kernel .fol .FOL .*
13
14
14
15
import java .io .File
15
16
import scala .util .matching .Regex
@@ -26,13 +27,15 @@ object KernelParser {
26
27
*/
27
28
def parseToKernel (formula : String ): K .Formula = convertToKernel(Parser .fof(formula))
28
29
30
+ def cleanVarname (f : String ): String = f.replaceAll(Identifier .counterSeparator.toString, " " )
31
+
29
32
/**
30
33
* @param formula a tptp formula in leo parser
31
34
* @return the same formula in LISA
32
35
*/
33
36
def convertToKernel (formula : FOF .Formula ): K .Formula = {
34
37
formula match {
35
- case FOF .AtomicFormula (f, args) => K .AtomicFormula (K .ConstantAtomicLabel (f , args.size), args map convertTermToKernel)
38
+ case FOF .AtomicFormula (f, args) => K .AtomicFormula (K .ConstantAtomicLabel (cleanVarname(f) , args.size), args map convertTermToKernel)
36
39
case FOF .QuantifiedFormula (quantifier, variableList, body) =>
37
40
quantifier match {
38
41
case FOF .! => variableList.foldRight(convertToKernel(body))((s, f) => K .Forall (K .VariableLabel (s), f))
@@ -63,8 +66,8 @@ object KernelParser {
63
66
K .ConnectorFormula (
64
67
K .Or ,
65
68
formula.map {
66
- case CNF .PositiveAtomic (formula) => K .AtomicFormula (K .ConstantAtomicLabel (formula.f, formula.args.size), formula.args.map(convertTermToKernel).toList)
67
- case CNF .NegativeAtomic (formula) => ! K .AtomicFormula (K .ConstantAtomicLabel (formula.f, formula.args.size), formula.args.map(convertTermToKernel).toList)
69
+ case CNF .PositiveAtomic (formula) => K .AtomicFormula (K .ConstantAtomicLabel (cleanVarname( formula.f) , formula.args.size), formula.args.map(convertTermToKernel).toList)
70
+ case CNF .NegativeAtomic (formula) => ! K .AtomicFormula (K .ConstantAtomicLabel (cleanVarname( formula.f) , formula.args.size), formula.args.map(convertTermToKernel).toList)
68
71
case CNF .Equality (left, right) => K .equality(convertTermToKernel(left), convertTermToKernel(right))
69
72
case CNF .Inequality (left, right) => ! K .equality(convertTermToKernel(left), convertTermToKernel(right))
70
73
}
@@ -76,7 +79,7 @@ object KernelParser {
76
79
* @return the same term in LISA
77
80
*/
78
81
def convertTermToKernel (term : CNF .Term ): K .Term = term match {
79
- case CNF .AtomicTerm (f, args) => K .Term (K .ConstantFunctionLabel (f , args.size), args map convertTermToKernel)
82
+ case CNF .AtomicTerm (f, args) => K .Term (K .ConstantFunctionLabel (cleanVarname(f) , args.size), args map convertTermToKernel)
80
83
case CNF .Variable (name) => K .VariableTerm (K .VariableLabel (name))
81
84
case CNF .DistinctObject (name) => ???
82
85
}
@@ -87,7 +90,7 @@ object KernelParser {
87
90
*/
88
91
def convertTermToKernel (term : FOF .Term ): K .Term = term match {
89
92
case FOF .AtomicTerm (f, args) =>
90
- K .Term (K .ConstantFunctionLabel (f , args.size), args map convertTermToKernel)
93
+ K .Term (K .ConstantFunctionLabel (cleanVarname(f) , args.size), args map convertTermToKernel)
91
94
case FOF .Variable (name) => K .VariableTerm (K .VariableLabel (name))
92
95
case FOF .DistinctObject (name) => ???
93
96
case FOF .NumberTerm (value) => ???
@@ -174,11 +177,15 @@ object KernelParser {
174
177
if (d.isDirectory) {
175
178
if (d.listFiles().isEmpty) println(" empty directory" )
176
179
d.listFiles.filter(_.isDirectory)
177
-
178
180
} else throw new Exception (" Specified path is not a directory." )
179
181
} else throw new Exception (" Specified path does not exist." )
180
182
181
- probfiles.map(d => gatherFormulas(spc, d.getPath)).toSeq
183
+ probfiles.zipWithIndex
184
+ .map((d, i) => {
185
+ println(" [ " + (i + 1 ) + " / " + probfiles.size + " ] Gathering formulas from " + d.getName())
186
+ gatherFormulas(spc, d.getPath)
187
+ })
188
+ .toSeq
182
189
}
183
190
184
191
def gatherFormulas (spc : Seq [String ], path : String ): Seq [Problem ] = {
@@ -187,14 +194,27 @@ object KernelParser {
187
194
if (d.isDirectory) {
188
195
if (d.listFiles().isEmpty) println(" empty directory" )
189
196
d.listFiles.filter(_.isFile)
190
-
191
197
} else throw new Exception (" Specified path is not a directory." )
192
198
} else throw new Exception (" Specified path does not exist." )
193
199
194
- val r = probfiles.foldRight(List .empty[Problem ])((p, current) => {
195
- val md = getProblemInfos(p)
196
- if (md.spc.exists(spc.contains)) problemToKernel(p, md) :: current
197
- else current
200
+ val r = probfiles.zipWithIndex.foldLeft(List .empty[Problem ])((current, p_i) => {
201
+ val (p, i) = p_i
202
+
203
+ // Progress bar
204
+ if ((i + 1 ) % 100 == 0 || i + 1 == probfiles.size) {
205
+ val pbarLength = 30
206
+ var pbarContent = " =" * (((i + 1 ) * pbarLength) / probfiles.size)
207
+ pbarContent += " " * (pbarLength - pbarContent.length)
208
+ println(" \t [" + pbarContent + " ] (" + (i + 1 ) + " / " + probfiles.size + " ) " + d.getName())
209
+ }
210
+
211
+ try {
212
+ val md = getProblemInfos(p)
213
+ if (md.spc.exists(spc.contains)) current :+ problemToKernel(p, md)
214
+ else current
215
+ } catch {
216
+ case _ => current
217
+ }
198
218
})
199
219
r
200
220
}
0 commit comments