当前位置: 首页 > wzjs >正文

郑州网站外包免费python在线网站

郑州网站外包,免费python在线网站,手机商城网站建设设计方案,网站后期维护包括上一篇笔记概括了分词方法。 确定一个简单的目标 先实现Comment类型和Category类型,因为最接近行和领域的概念本质。 struct Comment {content: String, } struct Category {name: String, }以上两者只不过是中间结果。 其中,Line_data::Category携带的S…

上一篇笔记概括了分词方法。

确定一个简单的目标

先实现Comment类型和Category类型,因为最接近行和领域的概念本质。

struct Comment {content: String,
}
struct Category {name: String,
}

以上两者只不过是中间结果。
其中,Line_data::Category携带的String应当为Element,但遵循从少到多的思路,先写成String。(其实是太菜了不会写)
Category用于创建Domain
以下是从分词结果到语法分析结果的桥梁。

enum LineData {Comment(Comment),Category(Category),
}
struct Line {indent: usize,data: LineData,
}

其中Line用于代表行。

语法分析

输入分词结果和缩进

fn into_lines(line_list: Vec<Vec<String>>, indent_list: Vec<usize>) -> Vec<Line> {let mut local: Vec<Line> = Vec::new();for (i, tokens) in line_list.iter().enumerate() {let indent = indent_list[i];let data = match tokens[0].as_str() {"/" => {LineData::Comment(Comment { content: tokens[1].clone() })}"+" => {LineData::Category(Category { name: tokens[1].clone() })}_ => {continue}};local.push(Line { indent, data });}local
}

检查函数如下

fn check_lines(lines: &Vec<Line>) {for line in lines.iter() {let indent_str = " ".repeat(line.indent);match &line.data {LineData::Comment(comment) => {println!("{}Comment: {}", indent_str, comment.content);}LineData::Category(category) => {println!("{}Category: {}", indent_str, category.name);}}}
}

测试

完整的测试代码如下。

fn main() {let test_input = String::from(r"
/ test_line_for_a_comment
+ test_category/ test_line_for_a_comment/ test_line_for_a_comment+ test_category/ test_line_for_a_comment/ test_line_for_a_comment/ test_line_for_a_comment/ test_line_for_a_comment/ test_line_for_a_comment+ test_category/ test_line_for_a_comment/ test_line_for_a_comment+ test_category
+ test_category/ test_line_for_a_comment
+ test_category_with_an_empty_category+ test_an_empty_category
/ test_line_for_a_comment
/ test_line_for_a_comment
/ test_line_for_a_comment
/ test_line_for_a_comment
");let (line_list, indent_list) = into_tokens(&test_input);check_tokens(&line_list, &indent_list);let lines: Vec<Line> = into_lines(line_list, indent_list);check_lines(&lines)
}fn into_tokens(lines_input: &str) -> (Vec<Vec<String>>, Vec<usize>) {let mut word_current = String::new();let mut line_current = Vec::new();let mut lines_list_splited = Vec::new();let mut indent_current = 0;let mut indent_list = Vec::new();let mut indent_state_in = true;for char in lines_input.chars() {if char == '\n' {if !word_current.is_empty() {line_current.push(word_current.clone());word_current.clear();}if !line_current.is_empty() {lines_list_splited.push(line_current.clone());indent_list.push(indent_current);}line_current.clear();indent_current = 0;indent_state_in = true;} else if char == ' ' {if indent_state_in {indent_current += 1;} else if !word_current.is_empty() {line_current.push(word_current.clone());word_current.clear();}} else {indent_state_in = false;word_current.push(char);}}if !word_current.is_empty() {line_current.push(word_current);}if !line_current.is_empty() {lines_list_splited.push(line_current);indent_list.push(indent_current);}(lines_list_splited, indent_list)
}
fn check_tokens(token_list: &Vec<Vec<String>>, indent_list: &Vec<usize>) {for i in 0..token_list.len() {println!("[{}: {}] {:?}", i + 1,  indent_list[i], token_list[i]);}
}struct Comment {content: String,
}
struct Category {name: String,
}
fn into_lines(line_list: Vec<Vec<String>>, indent_list: Vec<usize>) -> Vec<Line> {let mut local: Vec<Line> = Vec::new();for (i, tokens) in line_list.iter().enumerate() {let indent = indent_list[i];let data = match tokens[0].as_str() {"/" => {LineData::Comment(Comment { content: tokens[1].clone() })}"+" => {LineData::Category(Category { name: tokens[1].clone() })}_ => {continue}};local.push(Line { indent, data });}local
}
fn check_lines(lines: &Vec<Line>) {for line in lines.iter() {let indent_str = " ".repeat(line.indent);match &line.data {LineData::Comment(comment) => {println!("{}Comment: {}", indent_str, comment.content);}LineData::Category(category) => {println!("{}Category: {}", indent_str, category.name);}}}
}enum LineData {Comment(Comment),Category(Category),
}
struct Line {indent: usize,data: LineData,
}

测试结果如下。

Comment: test_line_for_a_comment
Category: test_categoryComment: test_line_for_a_commentComment: test_line_for_a_commentCategory: test_categoryComment: test_line_for_a_commentComment: test_line_for_a_commentComment: test_line_for_a_commentComment: test_line_for_a_commentComment: test_line_for_a_commentCategory: test_categoryComment: test_line_for_a_commentComment: test_line_for_a_commentCategory: test_category
Category: test_categoryComment: test_line_for_a_comment
Category: test_category_with_an_empty_categoryCategory: test_an_empty_category
Comment: test_line_for_a_comment
Comment: test_line_for_a_comment
Comment: test_line_for_a_comment
Comment: test_line_for_a_comment
http://www.dtcms.com/wzjs/476692.html

相关文章:

  • 大型网站建设平台把百度网址大全设为首页
  • 网页设计课程总结百度seo关键词排名
  • ftp服务器搭建设置网站信息竞价推广开户
  • 宝安做网站公司网站域名综合查询
  • 家乡的网站设计模板百度在线识图查图片
  • 微网站如何做推广石家庄百度推广排名优化
  • 深圳网站建设多少钱短视频培训课程
  • wordpress 文字围绕图片新野seo公司
  • win系统和mac那个做网站好google chrome官网
  • 机械毕业论文代做网站重庆白云seo整站优化
  • 做电影下载网站还赚钱吗二级域名网站查询入口
  • 在哪个网站可以做任务赚钱的软件定制开发公司
  • 网站建设制作设计优化百度口碑网
  • 做网站中二级导航链接到一级导航上海seo服务
  • 天津河东区网站建设深圳市社会组织总会
  • 网站群 米拓如何自己开发网站
  • 网站订单系统模板下载重庆关键词快速排名
  • 黑色大气网站源码运营和营销是一回事吗
  • 网站怎么做免费推广方案网站制作的费用
  • 深圳商城软件开发公司seo外链代发
  • 做企业福利网站起名百度提交收录入口
  • 建设网站技术公司网页模板图片
  • 运城做网站哪家好ip软件点击百度竞价推广
  • 网站怎么换空间商网络营销专家
  • 手机网站开发浏览器测试工具优化方案官网电子版
  • 上海网络企业优化公司小学生班级优化大师
  • 王野摩托车质量可靠吗seo刷网站
  • wordpress网站新闻太原seo报价
  • 白酒网站模板深圳最新消息今天
  • 强化乡镇政府网站建设和管理免费学生html网页制作成品