Skip to content

Commit 392b1d6

Browse files
Update + fix TPTP problem parser
1 parent f23659f commit 392b1d6

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ cache
2525

2626
# data extracted
2727
data_extract
28+
29+
# TPTP data
30+
lisa-utils/src/main/resources

lisa-utils/src/main/scala/lisa/utils/tptp/KernelParser.scala

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import lisa.utils.KernelHelpers.*
1010
import lisa.utils.KernelHelpers.given_Conversion_Identifier_String
1111
import lisa.utils.KernelHelpers.given_Conversion_String_Identifier
1212
import lisa.utils.tptp.*
13+
import lisa.kernel.fol.FOL.*
1314

1415
import java.io.File
1516
import scala.util.matching.Regex
@@ -26,13 +27,15 @@ object KernelParser {
2627
*/
2728
def parseToKernel(formula: String): K.Formula = convertToKernel(Parser.fof(formula))
2829

30+
def cleanVarname(f: String): String = f.replaceAll(Identifier.counterSeparator.toString, "")
31+
2932
/**
3033
* @param formula a tptp formula in leo parser
3134
* @return the same formula in LISA
3235
*/
3336
def convertToKernel(formula: FOF.Formula): K.Formula = {
3437
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)
3639
case FOF.QuantifiedFormula(quantifier, variableList, body) =>
3740
quantifier match {
3841
case FOF.! => variableList.foldRight(convertToKernel(body))((s, f) => K.Forall(K.VariableLabel(s), f))
@@ -63,8 +66,8 @@ object KernelParser {
6366
K.ConnectorFormula(
6467
K.Or,
6568
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)
6871
case CNF.Equality(left, right) => K.equality(convertTermToKernel(left), convertTermToKernel(right))
6972
case CNF.Inequality(left, right) => !K.equality(convertTermToKernel(left), convertTermToKernel(right))
7073
}
@@ -76,7 +79,7 @@ object KernelParser {
7679
* @return the same term in LISA
7780
*/
7881
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)
8083
case CNF.Variable(name) => K.VariableTerm(K.VariableLabel(name))
8184
case CNF.DistinctObject(name) => ???
8285
}
@@ -87,7 +90,7 @@ object KernelParser {
8790
*/
8891
def convertTermToKernel(term: FOF.Term): K.Term = term match {
8992
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)
9194
case FOF.Variable(name) => K.VariableTerm(K.VariableLabel(name))
9295
case FOF.DistinctObject(name) => ???
9396
case FOF.NumberTerm(value) => ???
@@ -174,11 +177,15 @@ object KernelParser {
174177
if (d.isDirectory) {
175178
if (d.listFiles().isEmpty) println("empty directory")
176179
d.listFiles.filter(_.isDirectory)
177-
178180
} else throw new Exception("Specified path is not a directory.")
179181
} else throw new Exception("Specified path does not exist.")
180182

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
182189
}
183190

184191
def gatherFormulas(spc: Seq[String], path: String): Seq[Problem] = {
@@ -187,14 +194,27 @@ object KernelParser {
187194
if (d.isDirectory) {
188195
if (d.listFiles().isEmpty) println("empty directory")
189196
d.listFiles.filter(_.isFile)
190-
191197
} else throw new Exception("Specified path is not a directory.")
192198
} else throw new Exception("Specified path does not exist.")
193199

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+
}
198218
})
199219
r
200220
}

0 commit comments

Comments
 (0)