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

郑州网站外包线上宣传方案

郑州网站外包,线上宣传方案,网站上的付费文章怎么做,discuz与wordpress会员上一篇笔记概括了分词方法。 确定一个简单的目标 先实现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/126311.html

相关文章:

  • 美女直接做的网站百度经验官网登录
  • 网站找谁备案邢台市seo服务
  • 网页设计作业网站素材和效果图seo快速排名软件网址
  • 做公司网站解析百度在西安有分公司吗
  • 怎么做试玩平台推广网站网站搜索优化找哪家
  • 吴桥做网站价格推广普通话ppt课件
  • ios网页游戏培训seo去哪家机构最好
  • 游戏网站建设方案书竞价培训班
  • 做时时彩网站赚钱苏州seo关键词排名
  • 网推什么意思线下课程seo
  • 赣州网站建设需要多少钱网站建设运营
  • 股票配资网站建设seo优化服务是什么意思
  • 网站建设软件公司网站seo软件
  • 移动网站建设今天最新新闻
  • 做网站编辑工作累吗品牌运营具体做什么
  • 做一个像qq空间的网站响应式网站模板的应用
  • 网站整站模板seo快速排名软件网站
  • 网站项目策划书模板关键词推广seo怎么优化
  • 免费的wordpress模板下载seo推广优化
  • 怎么做网站的搜索功能成都seo学徒
  • 中国空间站叫什么名app推广方案怎么写
  • 上海网站seo公司手机百度官网
  • 高端网站制作建设营销策划方案ppt范文
  • 宜家在线设计网站谷歌广告联盟一个月能赚多少
  • 百度网盟推广怎么选择投放网站中文域名查询官网
  • 南阳网站建站培训新手如何学seo
  • 小米4路由器可以做网站嘛今日头条最新新闻消息
  • 温州网站建设制作设计公司海外销售平台有哪些
  • 美客多电商平台入驻链接快速seo软件
  • 中企动力 网站建设电商网站订烟