diff --git a/Help/markdown/Table_of_Knowledge_Base_Functions.md b/Help/markdown/Table_of_Knowledge_Base_Functions.md index e360fa8..b882866 100644 --- a/Help/markdown/Table_of_Knowledge_Base_Functions.md +++ b/Help/markdown/Table_of_Knowledge_Base_Functions.md @@ -89,8 +89,10 @@ In the table below, a **name** must be a STR, **parent** is a CON, **attr_str** | [**renameattr(con, name, new)**](renameattr.md) | **NONE** | Rename con's named attribute to new. | | [**movecleft(con)**](movecleft.md) | **NONE** | Move concept before previous sibling. (Moves concept to the left in its list.) | | [**movecright(con)**](movecright.md) | **NONE** | Move concept after next sibling. (Moves concept to the right in its list.) | +| [**moveconcept(con, parent_c)**](moveconcept.md) | **CON** | Move concept, with its subtree, attributes and phrase, to be the last child of *parent_c*. Returns 0, changing nothing, for the root, a move into its own subtree, or a parent that already has a child of that name. **New in 4.2.21** | | [**sortchilds(con)**](sortchilds.md) | **NONE** | Sort concept's immediate children alphabetically. | | [**sorthier(con)**](sorthier.md) | **NONE** | Sort concept's subhierarchy alphabetically. | +| [**sortattrs(con)**](sortattrs.md) | **INT** | Sort concept's attributes alphabetically by name. Each attribute keeps its values in order. **New in 4.2.21** | | **Phrase and Node Functions** | | | | [**findphrase(con)**](findphrase.md) | **PHR** | Fetch concept's phrase. | | [**sortphrase(con)**](sortphrase.md) | **NONE** | Sort concept's phrase nodes alphabetically. | diff --git a/Help/markdown/index.md b/Help/markdown/index.md index 68c4df5..27c2fb6 100644 --- a/Help/markdown/index.md +++ b/Help/markdown/index.md @@ -294,11 +294,13 @@ to a topic. - **Change** - [attrchange](attrchange.md) - [movecleft](movecleft.md) + - [moveconcept](moveconcept.md) - [movecright](movecright.md) - [renameattr](renameattr.md) - [renamechild](renamechild.md) - [renameconcept](renameconcept.md) - [replaceval](replaceval.md) + - [sortattrs](sortattrs.md) - [sortchilds](sortchilds.md) - [sorthier](sorthier.md) - **Command File** diff --git a/Help/markdown/moveconcept.md b/Help/markdown/moveconcept.md new file mode 100644 index 0000000..a427f2f --- /dev/null +++ b/Help/markdown/moveconcept.md @@ -0,0 +1,57 @@ +[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md) + +# moveconcept + +## Purpose + +Move a concept, with all its children, attributes and phrase, so that it becomes the last child of another concept. + +## Syntax + +``` +returnedConcept = moveconcept(aConcept, newParent); +``` + +``` +returnedConcept - type: con +aConcept - type: con +newParent - type: con +``` + +## Returns + +The moved concept, or 0 if it was not moved. + +## Remarks + +The concept is moved, not copied. Everything under it comes along, and variables that already point to it, or to anything under it, still do. + +Nothing is changed, and 0 is returned, when: + +- *aConcept* is the root of the knowledge base; +- *newParent* is *aConcept* itself or one of its descendants; +- *newParent* already has a child with *aConcept*'s name. + +Moving a concept within its current parent makes it that parent's last child. To move a concept one place among its siblings, use [movecleft](movecleft.md) or [movecright](movecright.md). + +**NEW 4.2.21** + +## Example + +``` +@CODE +L("top") = makeconcept(findroot(), "top"); +L("a") = makeconcept(L("top"), "a"); +L("b") = makeconcept(L("a"), "b"); +makeconcept(L("b"), "b1"); +L("c") = makeconcept(L("top"), "c"); + +moveconcept(L("b"), L("c")); +"output.txt" << conceptpath(findconcept(L("b"), "b1")) << "\n"; +``` + +This writes `"concept" "top" "c" "b" "b1"`: `b` and its child `b1` are now under `c`, and `a` has no children. + +## See Also + +[movecleft](movecleft.md), [movecright](movecright.md), [renameconcept](renameconcept.md), [Knowledge Base Functions](Table_of_Knowledge_Base_Functions.md) diff --git a/Help/markdown/sortattrs.md b/Help/markdown/sortattrs.md new file mode 100644 index 0000000..e406ec5 --- /dev/null +++ b/Help/markdown/sortattrs.md @@ -0,0 +1,46 @@ +[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md) + +# sortattrs + +## Purpose + +Sort a concept's attributes alphabetically by name. + +## Syntax + +``` +returnedNum = sortattrs(aConcept); +``` + +``` +returnedNum - type: int +aConcept - type: con +``` + +## Returns + +1 if the sort succeeded, 0 otherwise. + +## Remarks + +Names are compared the way [sortchilds](sortchilds.md) compares child concepts, so the order ignores case. Each attribute keeps its values in their original order. Only the order in which the attributes are listed changes, so the order [findattrs](findattrs.md) and [nextattr](nextattr.md) walk them in, and the order they are saved in. Looking an attribute up by name gives the same result before and after. + +**NEW 4.2.21** + +## Example + +``` +@CODE +L("con") = makeconcept(findroot(), "word"); +addstrval(L("con"), "zeta", "z"); +addstrval(L("con"), "alpha", "2"); +addstrval(L("con"), "alpha", "1"); +addstrval(L("con"), "Mid", "m"); +sortattrs(L("con")); +``` + +Before sorting, the attributes are listed as `zeta`, `alpha`, `Mid`. After sorting, they are `alpha`, `Mid`, `zeta`, and `alpha` still has the values `2`, `1` in that order. + +## See Also + +[sortchilds](sortchilds.md), [sorthier](sorthier.md), [findattrs](findattrs.md), [Knowledge Base Functions](Table_of_Knowledge_Base_Functions.md)