Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Help/markdown/Table_of_Knowledge_Base_Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
2 changes: 2 additions & 0 deletions Help/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
57 changes: 57 additions & 0 deletions Help/markdown/moveconcept.md
Original file line number Diff line number Diff line change
@@ -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)
46 changes: 46 additions & 0 deletions Help/markdown/sortattrs.md
Original file line number Diff line number Diff line change
@@ -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)
Loading