/** * 从字节流中加载 * * @param byteArray * @param natureIndexArray * @return */ public static Attribute create(ByteArray byteArray, Nature[] natureIndexArray) { int currentTotalFrequency = byteArray.nextInt(); int length = byteArray.nextInt(); Attribute attribute = new Attribute(length); attribute.totalFrequency = currentTotalFrequency; for (int j = 0; j < length; ++j) { attribute.nature[j] = natureIndexArray[byteArray.nextInt()]; attribute.frequency[j] = byteArray.nextInt(); } return attribute; }
public static Attribute create(String natureWithFrequency) { try { String param[] = natureWithFrequency.split(" "); int natureCount = param.length / 2; Attribute attribute = new Attribute(natureCount); for (int i = 0; i < natureCount; ++i) { attribute.nature[i] = LexiconUtility.convertStringToNature(param[2 * i], null); attribute.frequency[i] = Integer.parseInt(param[1 + 2 * i]); attribute.totalFrequency += attribute.frequency[i]; } return attribute; } catch (Exception e) { logger.warning( "使用字符串" + natureWithFrequency + "创建词条属性失败!" + TextUtility.exceptionToString(e)); return null; } }