From 4d4fbb77cc27c1a972ae4775d42fdfd2fff84cce Mon Sep 17 00:00:00 2001 From: David de Hilster Date: Sun, 5 Sep 2021 14:59:10 -0400 Subject: [PATCH] VISUALTEXT-FILES-003 Enhancing KBFuncs Signed-off-by: David de Hilster --- spec/KBFuncs.nlp | 85 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/spec/KBFuncs.nlp b/spec/KBFuncs.nlp index 09bb074..e6cc763 100644 --- a/spec/KBFuncs.nlp +++ b/spec/KBFuncs.nlp @@ -18,6 +18,40 @@ AddUniqueCon(L("concept"),L("name")) { return L("con"); } +AddUniqueStr(L("concept"),L("attr"),L("value")) { + if (!strval(L("concept"),L("attr"))) + addstrval(L("concept"),L("attr"),L("value")); +} + +AddUniqueNum(L("concept"),L("attr"),L("value")) { + "unique.txt" << L("attr") << " " << str(L("value")) << " " << conceptpath(L("concept")) << "\n"; + L("val") = AttrValues(L("concept"),L("attr")); + while (L("val")) { + L("num") = getnumval(L("val")); + "unique.txt" << str(L("num")) << "\n"; + if (str(L("num")) == str(L("value"))) + return 0; + L("val") = nextval(L("val")); + } + addnumval(L("concept"),L("attr"),num(L("value"))); + return 1; +} + +CopyAttr(L("from"),L("to"),L("attr")) { + L("from value") = strval(L("from"),L("attr")); + L("to value") = strval(L("to"),L("attr")); + if (L("from value") && !L("to value")) + addstrval(L("to"),L("attr"),L("from value")); +} + +AttrValues(L("con"),L("attr")) { + L("at") = findattr(L("con"),L("attr")); + if (L("at")) + return attrvals(L("at")); + return 0; +} + + ############################################### # KB Dump Functins ############################################### @@ -44,6 +78,11 @@ IncrementCount(L("con"),L("countname")) { return L("count"); } +CountName(L("con"),L("root")) { + L("count") = IncrementCount(L("con"),L("root")); + return L("root") + str(L("count")); +} + TakeKB(L("filename")) { L("path") = G("$apppath") + "/kb/" + L("filename") + ".kb"; "kb.txt" << "Taking: " << L("path") << "\n"; @@ -69,6 +108,20 @@ ChildCount(L("con")) { ############################################### DisplayKB(L("top con"),L("full")) { + L("file") = DisplayFileName(); + DisplayKBRecurse(L("file"),L("top con"),0,L("full")); + L("file") << "\n"; + return L("top con"); +} + +KBPipeHeader(L("text")) { + L("file") = DisplayFileName(); + L("file") << "#######################\n"; + L("file") << "# " << L("text") << "\n"; + L("file") << "#######################\n\n"; +} + +DisplayFileName() { if (num(G("$passnum")) < 10) { L("file") = "ana00" + str(G("$passnum")); }else if (num(G("$passnum")) < 100) { @@ -77,9 +130,7 @@ DisplayKB(L("top con"),L("full")) { L("file") = "ana0" + str(G("$passnum")); } L("file") = L("file") + ".kbb"; - DisplayKBRecurse(L("file"),L("top con"),0,L("full")); - L("file") << "\n"; - return L("top con"); + return L("file"); } DisplayKBRecurse(L("file"),L("top"),L("level"),L("full")) { @@ -163,20 +214,32 @@ SpacesStr(L("num")) { # DICTIONARY FUNCTIONS ############################################### -WriteDictionaryWord(L("file"),L("word"),L("attrName"),L("value"),L("attrType")) { - addword(L("word")); - addword(L("attrName")); +DictionaryClear() { + G("dictionary path") = G("$apppath") + "\\kb\\user\\dictionary.kb"; + G("dictionary") = openfile(G("dictionary path")); +} + +DictionaryWord(L("word"),L("attrName"),L("value"),L("attrType")) { + L("file") = G("dictionary"); + + if (!dictfindword(L("word"))) + L("file") << "add word \"" + L("word") + "\"\n"; L("file") << "ind attr\n" << findwordpath(L("word")) << "\n0\n"; L("file") << findwordpath(L("attrName")) << "\n"; - if (L("attrType") == "string") - L("file") << "pst\n" << str(L("value")); - else if (L("attrType") == "number") - L("file") << "pnum\n" << numval(L("value")); - else if (L("attrType") == "concept") + if (L("attrType") == "str") + L("file") << "pst\n" << L("value"); + else if (L("attrType") == "num") + L("file") << "pnum\n" << str(L("value")); + else if (L("attrType") == "con") L("file") << "pcon\n" << conceptpath(L("value")); L("file") << "\nend ind\n\n"; } +DictionaryEnd() { + G("dictionary") << "\nquit\n\n"; + closefile(G("dictionary")); +} + @@DECL \ No newline at end of file