| | |
| | | public class ItemTypeParser extends Parser { |
| | | |
| | | /** |
| | | * 习题类型关键字 |
| | | * 习题类型关键字 |
| | | */ |
| | | private static Map<String,String> typeMap = new HashMap<String,String>(); |
| | | |
| | | static{ |
| | | typeMap.put("单选", ItemType.TYPE_SINGLE); |
| | | typeMap.put("单项选择", ItemType.TYPE_SINGLE); |
| | | typeMap.put("多选", ItemType.TYPE_MULTI); |
| | | typeMap.put("多项选择", ItemType.TYPE_MULTI); |
| | | typeMap.put("判断", ItemType.TYPE_TRUE_OR_FALSE); |
| | | typeMap.put("单选", ItemType.TYPE_SINGLE); |
| | | typeMap.put("单项选择", ItemType.TYPE_SINGLE); |
| | | typeMap.put("多选", ItemType.TYPE_MULTI); |
| | | typeMap.put("多项选择", ItemType.TYPE_MULTI); |
| | | typeMap.put("判断", ItemType.TYPE_TRUE_OR_FALSE); |
| | | } |
| | | |
| | | /** |
| | | * 习题开始模式匹配 |
| | | * 习题开始模式匹配 |
| | | */ |
| | | Pattern itemPattern = Pattern.compile("\\d+"); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 解析 ItemType |
| | | * 解析 ItemType |
| | | * |
| | | * @param doc |
| | | * @param str |
| | |
| | | */ |
| | | private ParseResult parse(ItemType itemType, String str) { |
| | | |
| | | // 习题 |
| | | // 习题 |
| | | Matcher matcher = itemPattern.matcher(str); |
| | | |
| | | if (matchBegin(matcher) && StringUtils.isNotEmpty(itemType.getType())) { |
| | |
| | | return new ParseResult(false, ParseResult.STEP_NEXT, item); |
| | | } |
| | | |
| | | // 题目类型 |
| | | // 题目类型 |
| | | for (String keyword : typeMap.keySet()) { |
| | | if (str.contains(keyword)) { |
| | | if(itemType.getType().equals(typeMap.get(keyword))){ |
| | |
| | | } |
| | | } |
| | | |
| | | //20150907修改:本来返回true,没有解析到一个类型,抛到上层 |
| | | //20150907修改:本来返回true,没有解析到一个类型,抛到上层 |
| | | return new ParseResult(false, ParseResult.STEP_PRE, null); |
| | | |
| | | } |