summaryrefslogtreecommitdiff
path: root/chain/src/item/default/mod.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-03-02 15:50:56 +0800
committerJSDurand <mmemmew@gmail.com>2023-03-02 15:50:56 +0800
commit57d600f261cca5d9076239e548c6e00646f774b6 (patch)
treef6f6b97c1f2bc4c3d8d9c71e5529e5e9facac2a2 /chain/src/item/default/mod.rs
parentb306fe88edcb3d7c7628e155f67fd7e1c8c29c19 (diff)
extra reductions
Finished the function of performing extra reductions. Still untested though.
Diffstat (limited to 'chain/src/item/default/mod.rs')
-rw-r--r--chain/src/item/default/mod.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/chain/src/item/default/mod.rs b/chain/src/item/default/mod.rs
index 22069d2..3903162 100644
--- a/chain/src/item/default/mod.rs
+++ b/chain/src/item/default/mod.rs
@@ -628,7 +628,7 @@ impl<T: GraphLabel> DefaultForest<ForestLabel<T>> {
/// case we clone it only when its degree is larger than one.
///
/// Return either the original node or the cloned node at the end.
- pub(crate) fn plant_if_needed(
+ pub(crate) fn plant_at_start(
&mut self,
node: usize,
mut fragment: Self,
@@ -691,6 +691,34 @@ impl<T: GraphLabel> DefaultForest<ForestLabel<T>> {
Ok(node)
}
+
+ /// Extract the node from `pavi`.
+ ///
+ /// If pavi is a parent, this returns the child pointed to by the
+ /// represented edge.
+ ///
+ /// If pavi is a virtual node, this simply returns the virtual
+ /// node.
+ ///
+ /// If pavi is empty, this returns the root, unless the forest is
+ /// empty.
+ ///
+ /// # Guarantee
+ ///
+ /// The returned node is guaranteed to be a valid node.
+ pub(crate) fn node_from_pavi(&self, pavi: PaVi) -> Result<usize, Error> {
+ match pavi {
+ PaVi::Parent(node, edge) => Ok(self.nth_child(node, edge)?),
+ PaVi::Virtual(_, _, node) => {
+ if node >= self.nodes_len() {
+ return Err(Error::IndexOutOfBounds(node, self.nodes_len()));
+ }
+
+ Ok(node)
+ }
+ PaVi::Empty => Ok(self.root().ok_or(Error::IndexOutOfBounds(0, 0))?),
+ }
+ }
}
pub mod splone;
@@ -831,6 +859,7 @@ impl DefaultForest<ForestLabel<GrammarLabel>> {
/// `child` is the index of the child node in question, and
/// `index` means that the child is the `index`-th child of the
/// node.
+ #[allow(dead_code)]
pub(crate) fn position_search(
&self,
node: usize,
@@ -1052,7 +1081,7 @@ impl DefaultForest<ForestLabel<GrammarLabel>> {
// }
/// Set the position of every node.
- pub(crate) fn set_pos(&mut self, pos: usize) -> Result<(), Error> {
+ pub(crate) fn set_pos(&mut self, pos: usize, allp: bool) -> Result<(), Error> {
let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph);
for node in 0..builder.nodes_len() {
@@ -1064,7 +1093,7 @@ impl DefaultForest<ForestLabel<GrammarLabel>> {
label_label.set_start(pos);
- if matches!(label_label.label().tnt(), Some(TNT::Ter(_))) {
+ if allp || matches!(label_label.label().tnt(), Some(TNT::Ter(_))) {
label_label.set_end(pos + 1);
} else if builder.degree(node)? == 1 && label_label.label().rule().is_some() {
let child = builder.children_of(node)?.next().unwrap();