Package com.articulate.sigma
Class KifFileChecker
java.lang.Object
com.articulate.sigma.KifFileChecker
Headless KIF checker that mirrors SUMOjEdit.checkErrorsBody logic,
but returns diagnostics as strings: "line:col: SEVERITY: message".
No UI / jEdit dependencies.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCheck KIF content without a filename.Runs syntax and semantic checks on KIF content, returning diagnostics.static voidCheckExistentialInAntecedent(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for existential quantifiers in antecedents (illegal).Run FormulaPreprocessor and record errors/warnings.static voidCheckIsValidFormula(String fileName, Formula f, int formulaStartLine, KB kb, String formulaText, List<ErrRec> msgs) Check if the formula is structurally valid in the KB.static voidCheckOrphanVars(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for disconnected variable groupsstatic voidCheckQuantifiedVariableNotInStatement(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for quantified variables that do not appear in the statement body.static voidCheckSingleUseVariables(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for variables that appear only once in a formula.static voidCheckSUMOtoTFAformErrors(String fileName, KB kb, Formula f, int formulaStartLine, Set<Formula> processed, List<ErrRec> msgs) Correct invocation of SUMO→TFA translation errors.static voidCheckSyntaxErrors(String contents, String fileName, List<ErrRec> msgs) Check for syntax errors during parsing.static voidCheckTermsBelowEntity(String fileName, Formula f, int formulaStartLine, String formulaText, KB kb, Set<String> localIndividuals, Set<String> localSubclasses, List<ErrRec> msgs) Check that all terms are below Entity in the KB hierarchy.static voidCheckUnquantInConsequent(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for unquantified variables appearing in the consequent of implications.static StringextractBufferSlice(String[] bufferLines, int startLine, int endLine) Extract a formula's exact text between line numbers.static intfindFormulaInBuffer(String formulaStr, String[] bufferLines) Find where a formula string appears in the buffer.static int[]findLineInFormula(String formulaText, String term) Find the relative line and column offset of a substring (e.g., error term) within a multi-line formula string.static StringPretty-print KIF contents using the KIF parser and Formula.toString().static intgetLineNum(String line) Extract line number from a parser error line.static intsigmaAntlr generates line offsetsstatic voidRecursively collect local individuals and subclasses from formulas.static booleanCheck if a token represents a constant rather than a variable or literal.static voidCommand-line entry point.static ErrRecparseKifError(String raw, String fileName) static voidshowHelp()Print CLI usage information.static KIFStringToKif(String contents, String fileName, List<ErrRec> errorList) Convert raw KIF string into a KIF object, collecting parse errors.
-
Field Details
-
debug
public static boolean debug
-
-
Constructor Details
-
KifFileChecker
public KifFileChecker()
-
-
Method Details
-
showHelp
public static void showHelp()Print CLI usage information. -
main
Command-line entry point. Usage examples: java com.articulate.sigma.KifFileChecker -h java com.articulate.sigma.KifFileChecker -c myfile.kif -
check
Check KIF content without a filename.- Parameters:
contents- the KIF text to check- Returns:
- list of error and warning diagnostics
-
check
Runs syntax and semantic checks on KIF content, returning diagnostics.- Parameters:
contents- raw KIF text to check- Returns:
- list of error/warning strings in "line:col: SEVERITY: message" format
-
formatKif
Pretty-print KIF contents using the KIF parser and Formula.toString(). Key behavior: - We only rewrite the top-level formula spans. - Everything outside those spans (comments, blank lines, etc.) is copied EXACTLY as in the original text. - If a formula span contains a ';' comment, we DO NOT reformat it. We keep the original slice to avoid moving inline comments. -
CheckQuantifiedVariableNotInStatement
public static void CheckQuantifiedVariableNotInStatement(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for quantified variables that do not appear in the statement body.- Parameters:
fileName- logical filenamef- formula to checkformulaText- raw text of the formulaformulaStartLine- buffer line offset of the formulamsgs- list to collect error records
-
CheckOrphanVars
public static void CheckOrphanVars(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for disconnected variable groups- Parameters:
fileName- logical filenamef- formula to checkformulaText- raw text of the formulaformulaStartLine- buffer line offset of the formulamsgs- list to collect error records
-
CheckExistentialInAntecedent
public static void CheckExistentialInAntecedent(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for existential quantifiers in antecedents (illegal).- Parameters:
fileName- logical filenamef- formula to checkformulaText- raw text of the formulaformulaStartLine- buffer line offsetmsgs- list to collect error records
-
CheckSingleUseVariables
public static void CheckSingleUseVariables(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for variables that appear only once in a formula.- Parameters:
fileName- logical filenamef- formula to checkformulaText- raw text of the formulaformulaStartLine- buffer line offsetmsgs- list to collect error records
-
CheckUnquantInConsequent
public static void CheckUnquantInConsequent(String fileName, Formula f, String formulaText, int formulaStartLine, List<ErrRec> msgs) Check for unquantified variables appearing in the consequent of implications.- Parameters:
fileName- logical filenamef- formula to checkformulaText- raw text of the formulaformulaStartLine- buffer line offsetmsgs- list to collect error records
-
CheckFormulaPreprocess
public static Set<Formula> CheckFormulaPreprocess(String fileName, KB kb, Formula f, int formulaStartLine, List<ErrRec> msgs) Run FormulaPreprocessor and record errors/warnings. Computes accurate absolute line/column using findLineInFormula() by locating the offending token inside the formula text.- Parameters:
fileName- logical filenamekb- knowledge basef- formula to preprocessformulaStartLine- buffer line offsetmsgs- list to collect error records- Returns:
- processed formula set
-
CheckSUMOtoTFAformErrors
public static void CheckSUMOtoTFAformErrors(String fileName, KB kb, Formula f, int formulaStartLine, Set<Formula> processed, List<ErrRec> msgs) Correct invocation of SUMO→TFA translation errors. Mirrors SUMOjEdit.checkErrorsBody() behavior. Steps: (1) Clear errors for this formula (2) Run SUMOtoTFAform.process(f,false) (3) Collect any populated SUMOtoTFAform.errors (4) Compute line/column using token matching (5) Clear for next formula -
CheckIsValidFormula
public static void CheckIsValidFormula(String fileName, Formula f, int formulaStartLine, KB kb, String formulaText, List<ErrRec> msgs) Check if the formula is structurally valid in the KB. Computes absolute line/column by matching the offending token inside the formula text using findLineInFormula().- Parameters:
fileName- logical filenamef- formulaformulaStartLine- buffer line offsetkb- knowledge baseformulaText- raw text of the formulamsgs- list to collect error records
-
CheckTermsBelowEntity
public static void CheckTermsBelowEntity(String fileName, Formula f, int formulaStartLine, String formulaText, KB kb, Set<String> localIndividuals, Set<String> localSubclasses, List<ErrRec> msgs) Check that all terms are below Entity in the KB hierarchy.- Parameters:
fileName- logical filenamef- formulaformulaStartLine- buffer line offsetformulaText- raw text of the formulakb- knowledge baselocalIndividuals- set of locally defined individualslocalSubclasses- set of locally defined subclassesmsgs- list to collect error records
-
CheckSyntaxErrors
Check for syntax errors during parsing.- Parameters:
contents- KIF textfileName- logical filenamemsgs- list to collect error records
-
StringToKif
Convert raw KIF string into a KIF object, collecting parse errors.- Parameters:
contents- KIF textfileName- logical filenamemsgs- list to collect error records- Returns:
- parsed KIF object
-
extractBufferSlice
Extract a formula's exact text between line numbers.- Parameters:
bufferLines- full text split into linesstartLine- starting line (1-based)endLine- ending line- Returns:
- text slice containing the formula
-
findLineInFormula
Find the relative line and column offset of a substring (e.g., error term) within a multi-line formula string.- Parameters:
formulaText- the full text of the formulaterm- the substring or token we are trying to locate (e.g. error term)- Returns:
- an int array [lineOffsetWithinFormula, columnOffsetWithinLine], or [-1,-1] if not found.
-
harvestLocalFacts
public static void harvestLocalFacts(Formula f, Set<String> localIndividuals, Set<String> localSubclasses) Recursively collect local individuals and subclasses from formulas.- Parameters:
f- formula to traverselocalIndividuals- set to populate with individualslocalSubclasses- set to populate with subclasses
-
isConst
Check if a token represents a constant rather than a variable or literal.- Parameters:
tok- token string- Returns:
- true if constant, false otherwise
-
findFormulaInBuffer
Find where a formula string appears in the buffer.- Parameters:
formulaStr- formula textbufferLines- full text split into lines- Returns:
- 1-based starting line index, or -1 if not found
-
getOffset
sigmaAntlr generates line offsets- Parameters:
line- error line text- Returns:
- the line offset of where the error/warning begins
-
getLineNum
Extract line number from a parser error line.- Parameters:
line- error line text- Returns:
- line number or 0 if not found
-
parseKifError
-