From ffaf4b552c2b0b10d453260715e305116e6a49d5 Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Fri, 12 Apr 2024 00:22:38 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20:bug:=20=E4=BF=AE=E5=A4=8DONA?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E8=BD=AC=E8=AF=91=E4=B8=AD=E5=AF=B9=20`Answe?= =?UTF-8?q?r:=20None.`=20=E7=9A=84=E3=80=8C=E4=BB=A5=E5=81=87=E4=B9=B1?= =?UTF-8?q?=E7=9C=9F=E3=80=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现在不再容忍 `Answer: None.` 作为一个「NAVM回答」被转译:其将被丢弃为「OTHER」类型 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/cin_implements/ona/translators.rs | 32 ++++++++++++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7bfb4b..230196c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "babel_nar" -version = "0.20.1" +version = "0.20.2" dependencies = [ "anyhow", "clap", @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "navm" -version = "0.11.0" +version = "0.12.0" dependencies = [ "anyhow", "nar_dev_utils", diff --git a/Cargo.toml b/Cargo.toml index 505979b..eef2a38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "babel_nar" -version = "0.20.1" +version = "0.20.2" edition = "2021" description = """ Implementation and application supports of the NAVM model diff --git a/src/cin_implements/ona/translators.rs b/src/cin_implements/ona/translators.rs index 0721261..86824d9 100644 --- a/src/cin_implements/ona/translators.rs +++ b/src/cin_implements/ona/translators.rs @@ -32,7 +32,7 @@ use anyhow::Result; use narsese::lexical::{Narsese, Term}; use navm::{ cmd::Cmd, - output::{Operation, Output}, + output::{type_names::ANTICIPATE, Operation, Output}, }; use pest::Parser; use regex::{Captures, Regex}; @@ -149,15 +149,15 @@ pub fn output_translate(content_raw: String) -> Result { // 根据冒号分隔一次,然后得到「头部」 let (head, tail) = content_raw.split_once(':').unwrap_or(("", "")); // 根据「头部」生成输出 + // * 🚩此处不直接使用NAVM输出中的「头部字串常量」主要考虑是「此为ONA特有」 let output = match head.to_lowercase().as_str() { - "answer" => Output::ANSWER { + // 回答,但排除「似是而非」的`Answer: None.` + // * 🚩ONA会输出带有误导性的`Answer: None.` + // * 看起来是回答,实际上不是 + // * 🚩【2024-04-11 23:01:50】现在将`Answer: None.`开除出「回答」的输出格式 + "answer" if !content_raw.contains("Answer: None.") => Output::ANSWER { // 先提取其中的Narsese | ⚠️借用了`content_raw` - // * 🚩ONA会输出带有误导性的`Answer: None.` - // * 看起来是回答,实际上不是 - narsese: match content_raw.contains("Answer: None.") { - true => None, - false => parse_narsese_ona(head, tail)?, - }, + narsese: parse_narsese_ona(head, tail)?, // 然后传入整个内容 content_raw, }, @@ -184,7 +184,7 @@ pub fn output_translate(content_raw: String) -> Result { // * 🚩对于「决策预期→ANTICIPATE」的特殊语法 // * 🚩【2024-04-02 18:45:17】仅截取`executed with args`,不截取`executed by NAR` _ if content_raw.contains("decision expectation=") => Output::UNCLASSIFIED { - r#type: "ANTICIPATE".into(), + r#type: ANTICIPATE.into(), narsese: parse_anticipate_ona(&content_raw)?, content: content_raw, }, @@ -266,7 +266,7 @@ pub fn parse_anticipate_ona(content_raw: &str) -> Result> { let narsese_content = captures[1].to_string(); // 解析 let parse_result = - parse_narsese_ona("ANTICIPATE", narsese_content.trim()).inspect_err(|e| { + parse_narsese_ona(ANTICIPATE, narsese_content.trim()).inspect_err(|e| { OutputType::Error.eprint_line(&format!("ONA「预期」解析失败:{e}")); }); // 返回 @@ -413,6 +413,7 @@ fn reform_output_to_narsese(out: &str) -> String { mod test { use super::*; use narsese::conversion::string::impl_lexical::format_instances::FORMAT_ASCII; + use navm::output::type_names::ANSWER; use util::asserts; /// 测试/正则重整 @@ -660,6 +661,10 @@ mod test { decision expectation=0.578198 implication: <(A &/ <(* {SELF}) --> ^op>) =/> G>. Truth: frequency=1.000000 confidence=0.241351 dt=1.000000 precondition: A. :|: Truth: frequency=1.000000 confidence=0.900000 occurrenceTime=4 ^op executed with args (* {SELF}) Input: <(* {SELF}) --> ^op>. :|: occurrenceTime=5 Priority=1.000000 Truth: frequency=1.000000, confidence=0.900000 + + A. + B? + Answer: None. " // 【2024-03-29 16:58:32】省略的「操作注册」语法:`*setopname 1 ^op` // 初步数据处理 .split('\n') @@ -670,9 +675,16 @@ mod test { for output in outputs { // ! 测试环境下[`parse_narsese_ona`]会强制要求「Narsese内容解析成功」 let o = output_translate(output.into()).expect("输出解析失败"); + // * 📌测试不能放过`Answer: None.`这个「不是回答的『回答』」 + // * 🚩「是回答」与「内容为`Answer: None.`」不能共存 + assert!(!(o.is_type(ANSWER) && o.raw_content().contains("None."))); + // 正常解析并展示Narsese if let Some(narsese) = o.get_narsese() { println!("{}", FORMAT_ASCII.format_narsese(narsese)) } + else { + println!("[{}] {}", o.type_name(), o.raw_content()) + } } } } From 751bbe623f72cb448e717a416a4d9655333587fe Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Sat, 13 Apr 2024 16:18:54 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20:arrow=5Fup:=20=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E6=96=B0=E7=89=88NAVM=20API=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E8=87=AA=E8=BA=ABNAVM=E5=90=AF=E5=8A=A8=E5=99=A8?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 4 +-- Cargo.toml | 2 +- src/bin/cin_launcher/main.rs | 2 +- src/cin_implements/cxin_js/launcher.rs | 3 ++- src/cin_implements/nars_python/launcher.rs | 3 ++- src/cin_implements/ona/launcher.rs | 3 ++- src/cin_implements/openjunars/launcher.rs | 3 ++- src/cin_implements/openjunars/mod.rs | 27 +++++++++++++++++-- src/cin_implements/opennars/launcher.rs | 3 ++- src/cin_implements/pynars/launcher.rs | 3 ++- .../cin_search/impls_path_builder/mod.rs | 4 +-- src/cli_support/cin_search/path_builder.rs | 2 +- src/lib.rs | 2 +- src/runtimes/command_vm/runtime.rs | 3 ++- 14 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 230196c..b127074 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "babel_nar" -version = "0.20.2" +version = "0.20.3" dependencies = [ "anyhow", "clap", @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "navm" -version = "0.12.0" +version = "0.13.0" dependencies = [ "anyhow", "nar_dev_utils", diff --git a/Cargo.toml b/Cargo.toml index eef2a38..ba761f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "babel_nar" -version = "0.20.2" +version = "0.20.3" edition = "2021" description = """ Implementation and application supports of the NAVM model diff --git a/src/bin/cin_launcher/main.rs b/src/bin/cin_launcher/main.rs index d45516c..b4f74fe 100644 --- a/src/bin/cin_launcher/main.rs +++ b/src/bin/cin_launcher/main.rs @@ -32,7 +32,7 @@ const TEST_PATH_PYNARS: (&str, &str) = (PYNARS_ROOT, "pynars.ConsolePlus"); /// 启动并获取NARS /// * 🚩【2024-03-27 18:55:07】目前就返回一个测试用的运行时 /// * 🎯敏捷开发用 -fn get_nars() -> impl VmLauncher { +fn get_nars() -> impl VmLauncher { // OpenNARS::new(TEST_PATH_OPENNARS) PyNARS::new(TEST_PATH_PYNARS.0, TEST_PATH_PYNARS.1) // ONA::new(TEST_PATH_ONA) diff --git a/src/cin_implements/cxin_js/launcher.rs b/src/cin_implements/cxin_js/launcher.rs index 2957f49..fe86628 100644 --- a/src/cin_implements/cxin_js/launcher.rs +++ b/src/cin_implements/cxin_js/launcher.rs @@ -39,7 +39,8 @@ impl CXinJS { } /// 启动到「命令行运行时」 -impl VmLauncher for CXinJS { +impl VmLauncher for CXinJS { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造并启动虚拟机 pipe! { diff --git a/src/cin_implements/nars_python/launcher.rs b/src/cin_implements/nars_python/launcher.rs index a0d9370..0a1d9eb 100644 --- a/src/cin_implements/nars_python/launcher.rs +++ b/src/cin_implements/nars_python/launcher.rs @@ -35,7 +35,8 @@ impl NARSPython { } /// 启动到「命令行运行时」 -impl VmLauncher for NARSPython { +impl VmLauncher for NARSPython { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令,并启动虚拟机 manipulate!( diff --git a/src/cin_implements/ona/launcher.rs b/src/cin_implements/ona/launcher.rs index dd6d87d..f1d500f 100644 --- a/src/cin_implements/ona/launcher.rs +++ b/src/cin_implements/ona/launcher.rs @@ -50,7 +50,8 @@ impl ONA { } /// 启动到「命令行运行时」 -impl VmLauncher for ONA { +impl VmLauncher for ONA { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造并启动虚拟机 let mut runtime = pipe! { diff --git a/src/cin_implements/openjunars/launcher.rs b/src/cin_implements/openjunars/launcher.rs index 3123b4d..6d9595f 100644 --- a/src/cin_implements/openjunars/launcher.rs +++ b/src/cin_implements/openjunars/launcher.rs @@ -37,7 +37,8 @@ impl OpenJunars { } /// 启动到「命令行运行时」 -impl VmLauncher for OpenJunars { +impl VmLauncher for OpenJunars { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令 let command = self.command_generator.generate_command(); diff --git a/src/cin_implements/openjunars/mod.rs b/src/cin_implements/openjunars/mod.rs index f9fad07..7804c79 100644 --- a/src/cin_implements/openjunars/mod.rs +++ b/src/cin_implements/openjunars/mod.rs @@ -42,11 +42,34 @@ mod tests { .expect("无法输入指令"); // 等待四秒钟,让Junars启动 - std::thread::sleep(std::time::Duration::from_secs(1)); + std::thread::sleep(std::time::Duration::from_secs(4)); vm.input_cmd(Cmd::NSE(nse_task!( B>.))) .expect("无法输入指令"); - std::thread::sleep(std::time::Duration::from_secs(6)); + + std::thread::sleep(std::time::Duration::from_secs(1)); + + vm.input_cmd(Cmd::CYC(1)).expect("无法输入指令"); + + std::thread::sleep(std::time::Duration::from_secs(1)); + + vm.input_cmd(Cmd::NSE(nse_task!( B>?))) + .expect("无法输入指令"); + + std::thread::sleep(std::time::Duration::from_secs(1)); + + vm.input_cmd(Cmd::CYC(1)).expect("无法输入指令"); + + std::thread::sleep(std::time::Duration::from_secs(3)); + + // 尝试截获其所有输出 + // * 🚩【2024-04-13 16:10:27】目前经由Julia侧`flush(stdout)`,仍然无法捕获 + // * 有输出`[ Info: Answer: B>. %1.0;0.9%`,但无法被程序捕获为文本 + while let Ok(Some(output)) = vm.try_fetch_output() { + dbg!(output); + } + + std::thread::sleep(std::time::Duration::from_secs(2)); // 终止虚拟机运行时 vm.terminate().expect("无法终止虚拟机"); diff --git a/src/cin_implements/opennars/launcher.rs b/src/cin_implements/opennars/launcher.rs index 181af44..649dbc4 100644 --- a/src/cin_implements/opennars/launcher.rs +++ b/src/cin_implements/opennars/launcher.rs @@ -43,7 +43,8 @@ impl OpenNARS { } /// 启动到「命令行运行时」 -impl VmLauncher for OpenNARS { +impl VmLauncher for OpenNARS { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令 // * 🚩细致的Java参数配置,都外包给[`CommandGeneratorJava`] diff --git a/src/cin_implements/pynars/launcher.rs b/src/cin_implements/pynars/launcher.rs index ed04dfc..e585422 100644 --- a/src/cin_implements/pynars/launcher.rs +++ b/src/cin_implements/pynars/launcher.rs @@ -36,7 +36,8 @@ impl PyNARS { } /// 启动到「命令行运行时」 -impl VmLauncher for PyNARS { +impl VmLauncher for PyNARS { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令 let command = self.command_generator.generate_command(); diff --git a/src/cli_support/cin_search/impls_path_builder/mod.rs b/src/cli_support/cin_search/impls_path_builder/mod.rs index 2d47af7..6acc588 100644 --- a/src/cli_support/cin_search/impls_path_builder/mod.rs +++ b/src/cli_support/cin_search/impls_path_builder/mod.rs @@ -29,7 +29,7 @@ pub fn file_name_matches(path: &Path, name: &str) -> bool { /// 从遍历者中找到匹配的所有启动器 /// * 🎯仅搜索出「可能有效,故构建好」的启动器 -pub fn launchers_from_walker>( +pub fn launchers_from_walker( path_walker: impl PathWalker, path_builder: impl CinPathBuilder, ) -> Vec<(L, usize)> { @@ -41,7 +41,7 @@ pub fn launchers_from_walker>( } /// 类似[`launchers_from_walker`],但根据返回的「匹配度」从高到底排序 -pub fn launchers_from_walker_sorted>( +pub fn launchers_from_walker_sorted( path_walker: impl PathWalker, path_builder: impl CinPathBuilder, ) -> Vec { diff --git a/src/cli_support/cin_search/path_builder.rs b/src/cli_support/cin_search/path_builder.rs index 004805f..c32f5b9 100644 --- a/src/cli_support/cin_search/path_builder.rs +++ b/src/cli_support/cin_search/path_builder.rs @@ -17,7 +17,7 @@ use std::path::Path; pub trait CinPathBuilder { /// 搜索结果的启动器类型 /// * 📌启动后变为[`CinSearch::Runtime`]运行时类型 - type Launcher: VmLauncher; + type Launcher: VmLauncher; /// 搜索结果的运行时类型 type Runtime: VmRuntime; diff --git a/src/lib.rs b/src/lib.rs index 6f24266..498173d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,7 @@ pub mod tests { PYNARS_MODULE = "pynars.ConsolePlus" NARS_PYTHON = "./executables/nars-python-main.exe" CXIN_JS = "./executables/cxin-nars-shell.js" - OPENJUNARS = "./executables/OpenJunars/run.jl" + OPENJUNARS = "./executables/OpenJunars/launch.jl" } } diff --git a/src/runtimes/command_vm/runtime.rs b/src/runtimes/command_vm/runtime.rs index 3a5cbf9..17d4574 100644 --- a/src/runtimes/command_vm/runtime.rs +++ b/src/runtimes/command_vm/runtime.rs @@ -96,7 +96,8 @@ impl VmRuntime for CommandVmRuntime { } /// 构建功能:启动命令行虚拟机 -impl VmLauncher for CommandVm { +impl VmLauncher for CommandVm { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { Ok(CommandVmRuntime { // 状态:正在运行 From d69a55aeb69d20a3dc09bf468ee454aa879738a6 Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:03:46 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20:bug:=20=E4=BF=AE=E5=A4=8DONA?= =?UTF-8?q?=E4=B8=AD=E5=9B=A0=E3=80=8CoccurenceTime=3DXXX=E3=80=8D?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E3=80=8C=E6=97=A0=E6=B3=95=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=B8=A6=E6=97=B6=E6=80=81=E8=AF=AD=E5=8F=A5=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E7=9C=9F=E5=80=BC=E3=80=8D=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cin_implements/ona/translators.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cin_implements/ona/translators.rs b/src/cin_implements/ona/translators.rs index 86824d9..961d6d0 100644 --- a/src/cin_implements/ona/translators.rs +++ b/src/cin_implements/ona/translators.rs @@ -376,6 +376,8 @@ fn reform_output_to_narsese(out: &str) -> String { let re_truth = Regex::new(r"Truth:\s*frequency=([0-9.]+),\s*confidence=([0-9.]+)").unwrap(); // 匹配ONA输出的「创建时间」⇒删去 let re_creation_t = Regex::new(r"creationTime=([0-9.]+)\s+").unwrap(); + // 匹配ONA输出的「发生时间」⇒删去 + let re_occurrence_t = Regex::new(r"occurrenceTime=([0-9.]+)\s+").unwrap(); // 匹配ONA输出的「时间递进」⇒删去 let re_dt = Regex::new(r"dt=([0-9.]+)\s+").unwrap(); // 匹配ONA输出的「优先级」⇒删去 @@ -396,6 +398,9 @@ fn reform_output_to_narsese(out: &str) -> String { // 删去非必要的「创建时间」 => [re_creation_t.replace_all](_, "") => #{&} // 必须借用 + // 删去非必要的「发生时间」 + => [re_occurrence_t.replace_all](_, "") + => #{&} // 必须借用 // 删去非必要的「递进时间」 => [re_dt.replace_all](_, "") => #{&} // 必须借用 @@ -681,8 +686,7 @@ mod test { // 正常解析并展示Narsese if let Some(narsese) = o.get_narsese() { println!("{}", FORMAT_ASCII.format_narsese(narsese)) - } - else { + } else { println!("[{}] {}", o.type_name(), o.raw_content()) } } From a957a58b3f08d89ee04ceb4838f0273d971620ca Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:06:14 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20:sparkles:=20=E5=9F=BA=E4=BA=8E?= =?UTF-8?q?=E3=80=8CNAVM=E8=BE=93=E5=87=BA=E3=80=8D=E7=9A=84=E3=80=8C?= =?UTF-8?q?=E8=AF=A6=E7=BB=86=E8=BE=93=E5=87=BA=E3=80=8D=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为`(e)print_cli!`在NAVM输出中使用前缀「%」实现「详细输出」,基于「NAVM输出」自身的「[# Narsese #]」与「[% NARS操作 %]」增加「CIN无关」的提示性输出(但总体信息量不比原始输出多) --- Cargo.lock | 33 ++++--- Cargo.toml | 4 +- src/bin/babelnar_cli/runtime_manage.rs | 5 ++ src/cli_support/io/output_print.rs | 117 +++++++++++++++++++++++-- 4 files changed, 139 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b127074..fd49e72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "babel_nar" -version = "0.20.3" +version = "0.21.0" dependencies = [ "anyhow", "clap", @@ -169,6 +169,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "clap" version = "4.5.4" @@ -211,9 +217,9 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clearscreen" -version = "2.0.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72f3f22f1a586604e62efd23f78218f3ccdecf7a33c4500db2d37d85a24fe994" +checksum = "2f8c93eb5f77c9050c7750e14f13ef1033a40a0aac70c6371535b6763a01438c" dependencies = [ "nix", "terminfo", @@ -568,7 +574,7 @@ dependencies = [ [[package]] name = "navm" -version = "0.13.0" +version = "0.14.1" dependencies = [ "anyhow", "nar_dev_utils", @@ -590,12 +596,13 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.4" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "cfg-if 1.0.0", + "cfg_aliases", "libc", ] @@ -1053,14 +1060,14 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "which" -version = "4.4.2" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +checksum = "8211e4f58a2b2805adfbefbc07bab82958fc91e3836339b1ab7ae32465dce0d7" dependencies = [ "either", "home", - "once_cell", "rustix", + "winsafe", ] [[package]] @@ -1229,6 +1236,12 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "ws" version = "0.9.2" diff --git a/Cargo.toml b/Cargo.toml index ba761f2..711f1c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "babel_nar" -version = "0.20.3" +version = "0.21.0" edition = "2021" description = """ Implementation and application supports of the NAVM model @@ -25,7 +25,7 @@ repository = "https://github.com/ARCJ137442/BabelNAR.rs" # 用于错误处理 thiserror = "1.0.58" anyhow = "1.0.81" -clearscreen = "2.0.1" +clearscreen = "3.0.0" [dependencies.nar_dev_utils] # 【2024-03-13 21:17:55】实用库现在独立为`nar_dev_utils` diff --git a/src/bin/babelnar_cli/runtime_manage.rs b/src/bin/babelnar_cli/runtime_manage.rs index 652e6ba..ede6128 100644 --- a/src/bin/babelnar_cli/runtime_manage.rs +++ b/src/bin/babelnar_cli/runtime_manage.rs @@ -93,6 +93,11 @@ where fn add_output_listener(output_cache: &mut OutputCache) { output_cache.output_handlers.add_handler(|output| { // 打印输出 + // * 🚩【2024-04-13 17:57:32】暂不启用「详细输出」模式:尚未解决「详细输出后过长,但因信息取舍不能省掉『原始信息』」的问题 + // * 💭CIN的「原始输出」总是信息量相对最多的(NAVM输出只取其中一个规则的子集) + // * 📌因此,开启「详细模式」必定造成「信息冗余」 + // TODO: 💡或许后续可用配置开关「详细模式/纯NAVM输出模式」,以实现「自定义输出形式」 + // * ✨这样的形式也方便调用其exe的其它外部程序解析exe输出(更为规范化) println_cli!(&output); // 继续返回 Some(output) diff --git a/src/cli_support/io/output_print.rs b/src/cli_support/io/output_print.rs index 884919f..32bcbf0 100644 --- a/src/cli_support/io/output_print.rs +++ b/src/cli_support/io/output_print.rs @@ -40,6 +40,8 @@ //! * 参考链接: use colored::Colorize; +use nar_dev_utils::manipulate; +use narsese::conversion::string::impl_lexical::format_instances::FORMAT_ASCII; use navm::output::Output; use std::fmt::Display; @@ -87,8 +89,77 @@ impl OutputType<'_> { /// 从NAVM输出格式化 /// * 🎯封装「从NAVM输出打印」 #[inline(always)] - pub fn format_from_navm_output(out: &Output) -> impl Display { - OutputType::from(out).format_line(out.raw_content().trim_end()) + pub fn format_navm_output(out: &Output) -> impl Display { + let message = manipulate!( + // 新建字符串对象 + String::new() + // 格式化头部 + => Self::format_navm_output_type(out, _) + // 格式化原始内容 + => Self::format_navm_output_content(out, _) + ); + // 载入着色 + OutputType::from(out).to_colored_str(message) + } + + /// 从NAVM输出格式化(详细) + /// * 🎯封装「从NAVM输出打印」 + /// * ✨提供「解析出的Narsese」与「解析出的NARS操作」信息 + #[inline(always)] + pub fn format_from_navm_output_verbose(out: &Output) -> impl Display { + let message = manipulate!( + // 新建字符串对象 + String::new() + // 格式化头部 + => Self::format_navm_output_type(out, _) + // 详细格式化:Narsese、NARS操作 + => Self::format_navm_output_verbose(out, _) + // 格式化原始内容 + => Self::format_navm_output_content(out, _) + ); + // 载入 + OutputType::from(out).to_colored_str(message) + } + + /// 从NAVM输出格式化(详细) + /// * 🎯封装「从NAVM输出打印」逻辑 + /// * 🚩基于「流式添加内容」的做法 + /// * 📄`[OUT]` + #[inline(always)] + fn format_navm_output_type(out: &Output, out_message: &mut String) { + // 返回创建的字符串 + *out_message += "["; + *out_message += out.type_name(); + *out_message += "] "; // ! 🚩使用尾缀空格,以避免「非必要连续空格」 + } + + /// 从NAVM输出格式化(详细) + /// * 🎯封装「从NAVM输出打印」逻辑 + /// * 🚩基于「流式添加内容」的做法 + /// * 📄`[# B>. #]` + #[inline(always)] + fn format_navm_output_verbose(out: &Output, out_message: &mut String) { + // * 🚩先添加Narsese + if let Some(narsese) = out.get_narsese() { + *out_message += "[# "; + *out_message += &(FORMAT_ASCII.format(narsese)); + *out_message += " #]"; + *out_message += " "; // 🚩使用尾缀空格,以避免「非必要连续空格」 + } + // * 🚩再添加操作 + if let Some(operation) = out.get_operation() { + *out_message += "[% "; + // 🚩↓使用尾缀空格,以避免「非必要连续空格」 + *out_message += &operation.to_string(); + *out_message += " %]"; + *out_message += " "; // 🚩使用尾缀空格,以避免「非必要连续空格」 + } + } + + /// * 📄ONA:`Input: G3! :|: occurrenceTime=37 Priority=1.000000 Truth: frequency=1.000000, confidence=0.900000` + fn format_navm_output_content(out: &Output, out_message: &mut String) { + // 最后添加原始内容 + *out_message += out.get_content().trim(); } /// 基于[`colored`]的输出美化 @@ -130,8 +201,16 @@ impl OutputType<'_> { /// ✨格式化打印NAVM输出 /// * 🎯BabelNAR CLI #[inline] - pub fn print_from_navm_output(out: &Output) { - println!("{}", Self::format_from_navm_output(out)); + pub fn print_navm_output(out: &Output) { + println!("{}", Self::format_navm_output(out)); + } + + /// ✨格式化打印NAVM输出(详细) + /// * 🎯BabelNAR CLI + /// * 🎯附带debug效果(检验「输出转译是否成功达到预期」) + #[inline] + pub fn print_navm_output_verbose(out: &Output) { + println!("{}", Self::format_from_navm_output_verbose(out)); } /// ✨格式化打印CLI输出(标准错误) @@ -144,34 +223,56 @@ impl OutputType<'_> { /// ✨格式化打印NAVM输出(标准错误) /// * 🎯BabelNAR CLI #[inline] - pub fn eprint_from_navm_output(out: &Output) { - eprintln!("{}", Self::format_from_navm_output(out)); + pub fn eprint_navm_output(out: &Output) { + eprintln!("{}", Self::format_navm_output(out)); + } + + /// ✨格式化打印NAVM输出(标准错误)(详细) + /// * 🎯BabelNAR CLI + /// * 🎯附带debug效果(检验「输出转译是否成功达到预期」) + #[inline] + pub fn eprint_navm_output_verbose(out: &Output) { + eprintln!("{}", Self::format_from_navm_output_verbose(out)); } } /// 快捷打印宏 #[macro_export] macro_rules! println_cli { + // 消息 | ✨可格式化 ([$enum_type_name:ident] $($tail:tt)*) => { // 调用内部函数 $crate::cli_support::io::output_print::OutputType::$enum_type_name.print_line(&format!($($tail)*)); }; + // NAVM输出 表达式 ($navm_output:expr) => { // 调用内部函数 - $crate::cli_support::io::output_print::OutputType::print_from_navm_output($navm_output); + $crate::cli_support::io::output_print::OutputType::print_navm_output($navm_output); + }; + // NAVM输出 表达式 | 🪄详细 + (% $navm_output:expr) => { + // 调用内部函数 + $crate::cli_support::io::output_print::OutputType::print_navm_output_verbose($navm_output); }; } /// 快捷打印宏/标准错误 #[macro_export] macro_rules! eprintln_cli { + // 消息 | ✨可格式化 ([$enum_type_name:ident] $($tail:tt)*) => { // 调用内部函数 $crate::cli_support::io::output_print::OutputType::$enum_type_name.eprint_line(&format!($($tail)*)); }; + // NAVM输出 表达式 ($navm_output:expr) => { // 调用内部函数 - $crate::cli_support::io::output_print::OutputType::eprint_from_navm_output($navm_output); + $crate::cli_support::io::output_print::OutputType::eprint_navm_output($navm_output); + }; + // NAVM输出 表达式 | 🪄详细 + (% $navm_output:expr) => { + // 调用内部函数 + $crate::cli_support::io::output_print::OutputType::eprint_navm_output_verbose($navm_output); }; } From 6d98b89be0a0c77b11ba6b5ead483e44214145d8 Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:11:47 +0800 Subject: [PATCH 5/6] =?UTF-8?q?docs:=20:memo:=20=E6=94=B9=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E9=BB=98=E8=AE=A4=E8=AF=AD=E8=A8=80=E4=B8=BA=E4=B8=AD?= =?UTF-8?q?=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重新将中文作为项目的默认文档语言 --- README.en-us.md | 11 ++++++++ README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++--- README.zh-cn.md | 65 ----------------------------------------------- 3 files changed, 75 insertions(+), 68 deletions(-) create mode 100644 README.en-us.md delete mode 100644 README.zh-cn.md diff --git a/README.en-us.md b/README.en-us.md new file mode 100644 index 0000000..d95f5b0 --- /dev/null +++ b/README.en-us.md @@ -0,0 +1,11 @@ +# BabelNAR.rs + +[简体中文](./README.md) | English + + 🏗️The **English document** of the project is still under preparation. PR is welcome. + +[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org) + +Implementation and application supports of the NAVM model + +⚠️【2024-04-03 15:12:55】**This documentation is still in progress. For full and latest content, please refer to [the Simplified Chinese version](README.zh-cn.md).** diff --git a/README.md b/README.md index e589b58..f8ba6af 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,70 @@ # BabelNAR.rs -English | [简体中文](README.zh-cn.md) +简体中文 | [English](./README-en-us.md) + + 🏗️项目的**英文文档**尚在筹建,有意者欢迎提交PR [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org) -Implementation and application supports of the NAVM model +该项目使用[语义化版本 2.0.0](https://semver.org/)进行版本号管理。 + +[**NAVM.rs**](https://github.com/ARCJ137442/NAVM.rs)对[CIN](#cin-computer-implement-of-nars)的**启动器**、**运行时**及应用程序实现 + +- 前身为[**BabelNAR.jl**](https://github.com/ARCJ137442/BabelNAR.jl) +- ✨为「非公理虚拟机模型」提供程序实现 +- ✨统一各[CIN](#cin-computer-implement-of-nars)的**输入输出**形式,聚合使用各大NARS实现 +- ✨提供一个方便使用的CLI工具,以便从配置中快速启动、测试各类NARS实现 + - 🎯一站式NARS**启动器** + - 🎯NARS**交叉测试**工具 + +## 概念 + +### CIN (Computer Implement of NARS) + +- 「NARS计算机实现」之英文缩写 +- 指代所有**实现NARS**的计算机软件系统 + - 不要求完整实现NAL 1~9 + +### ***CommonNarsese*** + +🔗参考[**NAVM.jl**的对应部分](https://github.com/ARCJ137442/navm.jl?tab=readme-ov-file#commonnarsese) + +## 各CIN对接情况 + +🕒最后更新时间:【2024-03-26 01:43:28】 + +| CIN | 实现方法 | 进程安全 | 输入转译 | 输出转译 | +| :---------- | :---------: | :--: | :--: | :--: | +| OpenNARS | `java -jar` | ✅ | ✅ | 🚧 | +| ONA | 直接启动exe | ✅ | ✅ | 🚧 | +| PyNARS | `python -m` | ✅ | 🚧 | 🚧 | +| NARS-Python | 直接启动exe | ❓ | ✅ | ❌ | +| OpenJunars | `julia` | ✅ | ❌ | ❌ | + +注: + +- 🚧输入输出转译功能仍然在从[BabelNAR_Implements](https://github.com/ARCJ137442/BabelNAR_Implements.jl)迁移 +- ❓NARS-Python的exe界面可能会在终止后延时关闭 +- ❌基于`julia`启动OpenJunars脚本`launch.jl`时,对「输出捕获」尚未有成功记录 +- ❌目前对NARS-Python的「输出捕获」尚未有成功记录 + +## CLI测试:各CIN完成度评估 + +🕒最后更新时间:【2024-04-07 16:52:29】 + +| | 简单演绎 | 高阶演绎 | 自变量消除 | 时间归纳 | 简单操作 | 时序操作 | +| :--- | :--: | :--: | :--: | :--: | :--: | :--: | +| 原理 | 继承关系的传递性 | 蕴含关系的蕴含保真 | 代入消元 | 前后事件的联系 | 直接要求「做某事」 | 在「发生某事,做某事,目标达成」中学会「若发生某事,就做某事」 | +| 对应NAL内容 | NAL-1 | NAL-5 | NAL-5 + NAL-6 | NAL-7 | NAL-8 | NAL-7 + NAL-8 | +| 语句输入 | ` B>.` + ` C>.` | `< B> ==> D>>.` + ` B>.` | `< $1> ==> <$1 --> C>>.` + ` B>.` | ` B>. :\|:` + ` D>. :\|:` | `<(*, ...) --> ^left>! :\|:` | `A. :\|:` + `<(*, {SELF}) --> ^left>. :\|:` + `G. :\|:` + `<(&/, A, <(*, ...) --> ^left>) ==> G>?` + `G! :\|:` | +| 预期输出 | ` C>.` | ` D>.` | ` C>.` | `< B> =/> D>>.` | EXE `<(*, ...) --> ^left> :\|:` | EXE `<(&/, A, <(*, ...) --> ^left>) ==> G>` | +| OpenNARS(3.0.4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| ONA | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | +| PyNARS | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | +| CXinNARS | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | + +## 参考 -⚠️【2024-04-03 15:12:55】**This documentation is still in progress. For full and latest content, please refer to [the Simplified Chinese version](README.zh-cn.md).** +- [BabelNAR](https://github.com/ARCJ137442/BabelNAR.jl) +- [BabelNAR_Implements](https://github.com/ARCJ137442/BabelNAR_Implements.jl) +- [NAVM.rs](https://github.com/ARCJ137442/NAVM.rs) diff --git a/README.zh-cn.md b/README.zh-cn.md deleted file mode 100644 index 1e1d5c3..0000000 --- a/README.zh-cn.md +++ /dev/null @@ -1,65 +0,0 @@ -# BabelNAR.rs - -[English](README.md) | 简体中文 - -[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org) - -该项目使用[语义化版本 2.0.0](https://semver.org/)进行版本号管理。 - -[**NAVM.rs**](https://github.com/ARCJ137442/NAVM.rs)对[CIN](#cin-computer-implement-of-nars)的**启动器**、**运行时**及应用程序实现 - -- 前身为[**BabelNAR.jl**](https://github.com/ARCJ137442/BabelNAR.jl) -- ✨为「非公理虚拟机模型」提供程序实现 -- ✨统一各[CIN](#cin-computer-implement-of-nars)的**输入输出**形式,聚合使用各大NARS实现 - -## 概念 - -### CIN (Computer Implement of NARS) - -- 「NARS计算机实现」之英文缩写 -- 指代所有**实现NARS**的计算机软件系统 - - 不要求完整实现NAL 1~9 - -### ***CommonNarsese*** - -🔗参考[**NAVM.jl**的对应部分](https://github.com/ARCJ137442/navm.jl?tab=readme-ov-file#commonnarsese) - -## 各CIN对接情况 - -🕒最后更新时间:【2024-03-26 01:43:28】 - -| CIN | 实现方法 | 进程安全 | 输入转译 | 输出转译 | -| :---------- | :---------: | :--: | :--: | :--: | -| OpenNARS | `java -jar` | ✅ | ✅ | 🚧 | -| ONA | 直接启动exe | ✅ | ✅ | 🚧 | -| PyNARS | `python -m` | ✅ | 🚧 | 🚧 | -| NARS-Python | 直接启动exe | ❓ | ✅ | ❌ | -| OpenJunars | `julia` | ✅ | ❌ | ❌ | - -注: - -- 🚧输入输出转译功能仍然在从[BabelNAR_Implements](https://github.com/ARCJ137442/BabelNAR_Implements.jl)迁移 -- ❓NARS-Python的exe界面可能会在终止后延时关闭 -- ❌基于`julia`启动OpenJunars脚本`launch.jl`时,对「输出捕获」尚未有成功记录 -- ❌目前对NARS-Python的「输出捕获」尚未有成功记录 - -## CLI测试:各CIN完成度评估 - -🕒最后更新时间:【2024-04-07 16:52:29】 - -| | 简单演绎 | 高阶演绎 | 自变量消除 | 时间归纳 | 简单操作 | 时序操作 | -| :--- | :--: | :--: | :--: | :--: | :--: | :--: | -| 原理 | 继承关系的传递性 | 蕴含关系的蕴含保真 | 代入消元 | 前后事件的联系 | 直接要求「做某事」 | 在「发生某事,做某事,目标达成」中学会「若发生某事,就做某事」 | -| 对应NAL内容 | NAL-1 | NAL-5 | NAL-5 + NAL-6 | NAL-7 | NAL-8 | NAL-7 + NAL-8 | -| 语句输入 | ` B>.` + ` C>.` | `< B> ==> D>>.` + ` B>.` | `< $1> ==> <$1 --> C>>.` + ` B>.` | ` B>. :\|:` + ` D>. :\|:` | `<(*, ...) --> ^left>! :\|:` | `A. :\|:` + `<(*, {SELF}) --> ^left>. :\|:` + `G. :\|:` + `<(&/, A, <(*, ...) --> ^left>) ==> G>?` + `G! :\|:` | -| 预期输出 | ` C>.` | ` D>.` | ` C>.` | `< B> =/> D>>.` | EXE `<(*, ...) --> ^left> :\|:` | EXE `<(&/, A, <(*, ...) --> ^left>) ==> G>` | -| OpenNARS(3.0.4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| ONA | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | -| PyNARS | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | -| CXinNARS | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | - -## 参考 - -- [BabelNAR](https://github.com/ARCJ137442/BabelNAR.jl) -- [BabelNAR_Implements](https://github.com/ARCJ137442/BabelNAR_Implements.jl) -- [NAVM.rs](https://github.com/ARCJ137442/NAVM.rs) From ff22133eff2e3d443eb01503e7e94324564f17a3 Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:21:34 +0800 Subject: [PATCH 6/6] =?UTF-8?q?docs:=20:memo:=20=E5=AF=B9=E8=87=AA?= =?UTF-8?q?=E8=BF=B0=E6=96=87=E6=A1=A3=E5=88=9D=E6=AD=A5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E3=80=8C=E4=BD=BF=E7=94=A8=E3=80=8D=E7=AB=A0=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index f8ba6af..d6af670 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,20 @@ - 🎯一站式NARS**启动器** - 🎯NARS**交叉测试**工具 + + + + +## 使用 + +### CLI + +- 使用 JSON/HJSON 配置文件 (`.json`/`.hjson`) + - 格式可参考项目测试代码 +- Rust调用侧:可参考项目测试代码 + +🏗️TODO(接受贡献) + ## 概念 ### CIN (Computer Implement of NARS)