| | |
| | | public class OptionParser extends Parser { |
| | | |
| | | /** |
| | | * 习题选项编号模式[带括号] |
| | | * 习题选项编号模式[带括号] |
| | | */ |
| | | //Pattern optNoWithBrackets = Pattern.compile("\\(?[ABCDEFabcdef]\\)?[、..]"); |
| | | //Pattern optNoWithBrackets = Pattern.compile("\\(?[ABCDEFabcdef]\\)?[、..]"); |
| | | |
| | | /** |
| | | * 习题选项 word自带的格式的 a.a、a) 这三种较为普遍,目前03可以解析成功,07解析失败*[\t] |
| | | * 习题选项 word自带的格式的 a.a、a) 这三种较为普遍,目前03可以解析成功,07解析失败*[\t] |
| | | */ |
| | | Pattern optNoWithBrackets = Pattern.compile("\\(?[ABCDEFGHIJKLMNOabcdefghijklmno]\\)?[..、]"); |
| | | Pattern optNoWithBrackets = Pattern.compile("\\(?[ABCDEFGHIJKLMNOabcdefghijklmno]\\)?[..、]"); |
| | | |
| | | /** |
| | | * 习题选项编号模式 |
| | | * 习题选项编号模式 |
| | | */ |
| | | Pattern optNo = Pattern.compile("[ABCDEFGHIJKLMNOabcdefghijklmno]"); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 解析 Item |
| | | * 解析 Item |
| | | * @param item |
| | | * @param str |
| | | * @return |
| | | */ |
| | | private ParseResult parse(Option option, String str) { |
| | | |
| | | //习题选项 |
| | | //习题选项 |
| | | Matcher optNoWithBracketsMatch = optNoWithBrackets.matcher(str); |
| | | |
| | | //尝试调用上级解析器继续解析 |
| | | //尝试调用上级解析器继续解析 |
| | | if(!matchBegin(optNoWithBracketsMatch)){ |
| | | return new ParseResult(false,ParseResult.STEP_PRE,null); |
| | | } |
| | |
| | | preOpt = opt; |
| | | start = optNoWithBracketsMatch.end(); |
| | | |
| | | // 在最开始匹配成功即跳出循环 |
| | | // 在最开始匹配成功即跳出循环 |
| | | //break ; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 去除文本中多余字符 |
| | | * 去除文本中多余字符 |
| | | * @param content |
| | | * @return |
| | | */ |
| | | private String beautyContent(String str){ |
| | | String prefix = ".。~、、..)"; |
| | | String prefix = ".。~、、..)"; |
| | | String content = str; |
| | | while(content.length()>0 && prefix.contains(content.substring(0, 1))){ |
| | | content = content.substring(1); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取题目选项 |
| | | * 获取题目选项 |
| | | * @param no |
| | | * @param item |
| | | * @return |