Package com.articulate.sigma.nlg
Class LanguageFormatter
java.lang.Object
com.articulate.sigma.nlg.LanguageFormatter
A class that handles the generation of natural language from logic.
- Author:
- Adam Pease - apease [at] articulatesoftware [dot] com, with thanks to Michal Sevcenko - sevcenko@vc.cvut.cz for development of the formatting language.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic classstatic class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleangenerateFormalNaturalLanguage(List<String> args, String pred, boolean isNegMode) generateFormalNaturalLanguage(List<String> args, String pred, boolean isNegMode, com.articulate.sigma.nlg.LanguageFormatter.RenderMode mode) static StringgenerateProofSummary(List<String> proofSteps) Generate a natural language summary of a proof using Ollama LLMhtmlParaphrase(String href) Hyperlink terms in a natural language format string.static voidA test method.paraphraseStatement(String stmt, boolean isNegMode, boolean isQuestionMode, int depth) Create a natural language paraphrase of a logical statement.static StringremovePreamble(String input) Remove the type declarations from the textvoidsetDoInformalNLG(boolean doIt) static voidstatic voidshowHelp()static voidtest1()static voidtest2()static voidtest3()static voidtest4()static Stringgenerate English paraphrasestatic StringtranslateWord(Map<String, String> termMap, String word) Return the NL format of an individual word.static StringvariableReplace(String form, Map<String, Set<String>> instMap, Map<String, Set<String>> classMap, KB kb, String language) Replace variables in a formula with paraphrases expressing their type.
-
Field Details
-
debug
public static boolean debug -
outputMap
-
tptpStep
public static tptp_parser.TPTPFormula tptpStep -
paraphraseLLM
public static boolean paraphraseLLM
-
-
Constructor Details
-
LanguageFormatter
public LanguageFormatter(String stmt, Map<String, String> phraseMap, Map<String, String> termMap, KB kb, String language) - Parameters:
stmt- The statement to be formatted.phraseMap- kb.getFormatMap() for this languagetermMap- kb.getTermFormatMap() for this languagekb-language-
-
-
Method Details
-
setDoInformalNLG
public void setDoInformalNLG(boolean doIt) -
htmlParaphrase
Hyperlink terms in a natural language format string. This assumes that terms to be hyperlinked are in the form invalid input: '&'%termName$termString , where termName is the name of the term to be browsed in the knowledge base and termString is the text that should be displayed hyperlinked.- Parameters:
href- the anchor string up to the term= parameter, which this method will fill in.- Returns:
-
paraphraseStatement
public String paraphraseStatement(String stmt, boolean isNegMode, boolean isQuestionMode, int depth) Create a natural language paraphrase of a logical statement.- Parameters:
stmt- The statement to be paraphrased.isNegMode- Whether the statement is negated.depth- An int indicating the level of nesting, for control of indentation.- Returns:
- A String, which is the paraphrased statement.
-
checkOllamaHealth
public static boolean checkOllamaHealth() -
generateProofSummary
Generate a natural language summary of a proof using Ollama LLM- Parameters:
proofSteps- List of proof steps as strings- Returns:
- HTML formatted proof summary
-
generateFormalNaturalLanguage
-
generateFormalNaturalLanguage
-
translateWord
Return the NL format of an individual word. -
removePreamble
Remove the type declarations from the text -
variableReplace
public static String variableReplace(String form, Map<String, Set<String>> instMap, Map<String, Set<String>> classMap, KB kb, String language) Replace variables in a formula with paraphrases expressing their type. -
test1
public static void test1() -
test2
public static void test2() -
test3
public static void test3() -
test4
public static void test4() -
setKB
-
toEnglish
generate English paraphrase -
showHelp
public static void showHelp() -
main
A test method.
-