Skip to content

Commit

Permalink
Merge pull request #5 from dehilsterlexis/VISUALTEXT-FILES-004
Browse files Browse the repository at this point in the history
VISUALTEXT-FILES-004 KBFuncs.nlp enhanced
  • Loading branch information
David de Hilster authored Sep 20, 2021
2 parents 93daf29 + 93c2064 commit 91cea11
Showing 1 changed file with 79 additions and 19 deletions.
98 changes: 79 additions & 19 deletions spec/KBFuncs.nlp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand All @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 91cea11

Please sign in to comment.