From 93c20645066c882e01265540e0f65a5836c4f7ef Mon Sep 17 00:00:00 2001 From: David de Hilster Date: Mon, 20 Sep 2021 09:48:28 -0400 Subject: [PATCH] VISUALTEXT-FILES-004 KBFuncs.nlp enhanced Signed-off-by: David de Hilster --- spec/KBFuncs.nlp | 98 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 19 deletions(-) diff --git a/spec/KBFuncs.nlp b/spec/KBFuncs.nlp index 9077391..07fc591 100644 --- a/spec/KBFuncs.nlp +++ b/spec/KBFuncs.nlp @@ -19,7 +19,7 @@ AddUniqueCon(L("concept"),L("name")) { } AddUniqueStr(L("concept"),L("attr"),L("value")) { - if (!strval(L("concept"),L("attr"))) + if (L("value") && !strval(L("concept"),L("attr"))) addstrval(L("concept"),L("attr"),L("value")); } @@ -28,20 +28,54 @@ AddUniqueNum(L("concept"),L("attr"),L("value")) { 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"))) + "unique.txt" << " value: " << str(L("num")) << "\n"; + if (L("num") == L("value")) return 0; L("val") = nextval(L("val")); } - addnumval(L("concept"),L("attr"),num(L("value"))); + addnumval(L("concept"),L("attr"),L("value")); + return 1; +} + +AddUniqueConVal(L("concept"),L("attr"),L("value")) { + "unique.txt" << L("attr") << " " << conceptpath(L("concept")) << " ==> " << L("attr") << " -- " << conceptpath(L("value")) << "\n"; + L("val") = AttrValues(L("concept"),L("attr")); + while (L("val")) { + L("con") = getconval(L("val")); + "unique.txt" << conceptname(L("con")) << "\n"; + if (conceptpath(L("con")) == conceptpath(L("value"))) + return 0; + L("val") = nextval(L("val")); + } + addconval(L("concept"),L("attr"),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")); + if (L("from value")) { + L("to value") = strval(L("to"),L("attr")); + if (L("from value") && !L("to value")) + addstrval(L("to"),L("attr"),L("from value")); + } +} + +CopyAttrNew(L("from"),L("to"),L("attr from"),L("attr to")) { + L("from value") = strval(L("from"),L("attr from")); + if (L("from value")) { + L("to value") = strval(L("to"),L("attr to")); + if (L("from value") && !L("to value")) + addstrval(L("to"),L("attr to"),L("from value")); + } +} + +CopyConAttr(L("from"),L("to"),L("attr")) { + L("from value") = conval(L("from"),L("attr")); + if (L("from value")) { + L("to value") = conval(L("to"),L("attr")); + if (L("from value") && !L("to value")) + addconval(L("to"),L("attr"),L("from value")); + } } AttrValues(L("con"),L("attr")) { @@ -51,18 +85,18 @@ AttrValues(L("con"),L("attr")) { return 0; } -############################################### -# KB Dump Functins -############################################### - -DumpKB(L("con"),L("file")) { - L("dir") = G("$apppath") + "/kb/"; - L("filename") = L("dir") + L("file") + ".kb"; - if (!kbdumptree(L("con"),L("filename"))) { - "kb.txt" << "FAILED dump: " << L("filename") << "\n"; - } else { - "kb.txt" << "DUMPED: " << L("filename") << "\n"; +LastChild(L("parent")) { + L("child") = down(L("parent")); + while (L("child")) { + L("last") = L("child"); + L("child") = next(L("child")); } + return L("last"); +} + +MakeCountCon(L("con"),L("count name")) { + L("count name") = CountName(L("con"),L("count name")); + return makeconcept(L("con"),L("count name")); } IncrementCount(L("con"),L("countname")) { @@ -82,6 +116,32 @@ CountName(L("con"),L("root")) { return L("root") + str(L("count")); } +StripEndDigits(L("name")) { + if (strisdigit(L("name"))) return 0; + L("len") = strlength(L("name")) - 1; + L("i") = L("len") - 1; + L("str") = strpiece(L("name"),L("i"),L("len")); + while (strisdigit(L("str")) && L("i")) { + L("i")--; + L("str") = strpiece(L("name"),L("i"),L("len")); + } + return strpiece(L("name"),0,L("i")); +} + +############################################### +# KB Dump Functins +############################################### + +DumpKB(L("con"),L("file")) { + L("dir") = G("$apppath") + "/kb/"; + L("filename") = L("dir") + L("file") + ".kb"; + if (!kbdumptree(L("con"),L("filename"))) { + "kb.txt" << "FAILED dump: " << L("filename") << "\n"; + } else { + "kb.txt" << "DUMPED: " << L("filename") << "\n"; + } +} + TakeKB(L("filename")) { L("path") = G("$apppath") + "/kb/" + L("filename") + ".kb"; "kb.txt" << "Taking: " << L("path") << "\n"; @@ -113,7 +173,7 @@ DisplayKB(L("top con"),L("full")) { return L("top con"); } -KBPipeHeader(L("text")) { +KBHeader(L("text")) { L("file") = DisplayFileName(); L("file") << "#######################\n"; L("file") << "# " << L("text") << "\n";