/** * Clear the data */ public void clearData() { getFeatureSet().clear(); m_featureBits.clear(); getFeatureSet().clear(); }
public void read(DataInputStream din) throws IOException { int size = din.readInt(); for(int i=0; i<size;i++) { String k = din.readUTF(); int size2 = din.readInt(); HashMap<String,Integer> h = new HashMap<String,Integer>(); getFeatureSet().put(k,h); for(int j = 0;j<size2;j++) { h.put(din.readUTF(), din.readInt()); } getFeatureCounter().put(k, size2); } calculateBits(); }
/** * Write the data * @param dos * @throws IOException */ public void writeData(DataOutputStream dos) throws IOException { dos.writeInt(getFeatureSet().size()); for(Entry<String, HashMap<String,Integer>> e : getFeatureSet().entrySet()) { dos.writeUTF(e.getKey()); dos.writeInt(e.getValue().size()); for(Entry<String,Integer> e2 : e.getValue().entrySet()) { if(e2.getKey()==null) DB.println("key "+e2.getKey()+" value "+e2.getValue()+" e -key "+e.getKey()); dos.writeUTF(e2.getKey()); dos.writeInt(e2.getValue()); } } } public void read(DataInputStream din) throws IOException {
public ArrayList<String> tagStrings(InstancesTagger is,int instanceIndex, int word, String wordForm) { ArrayList<POS> plist = pipe.classify( wordForm , params, word, is, instanceIndex, is.pposs[instanceIndex], li); String pos[] = mf.reverse(this.pipe.mf.getFeatureSet().get(ExtractorT2.POS)); ArrayList<String> postags =null; for(POS p : plist) { try { postags.add(pos[p.p]); }catch(Exception e) { e.printStackTrace(); } } return postags; }
/** * Register an attribute class, if it not exists and add a possible value * @param type * @param type2 */ final public int register(String a, String v) { HashMap<String,Integer> fs = getFeatureSet().get(a); if (fs==null) { fs = new HashMap<String,Integer>(); getFeatureSet().put(a, fs); fs.put(NONE, 0); getFeatureCounter().put(a, 1); } Integer c = getFeatureCounter().get(a); Integer i = fs.get(v); if (i==null) { fs.put(v, c); c++; getFeatureCounter().put(a,c); return c-1; } else return i; }
public void readModel(OptionsSuper options) { try{ pipe = new ExtractorT2(options, mf =new MFO()); _options=options; // load the model ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(options.modelName))); zis.getNextEntry(); DataInputStream dis = new DataInputStream(new BufferedInputStream(zis)); pipe.mf.read(dis); pipe.initValues(); pipe.initFeatures(); params = new ParametersFloat(0); params.read(dis); li = new Long2Int(params.parameters.length); pipe.read(dis); dis.close(); pipe.types = new String[pipe.mf.getFeatureCounter().get(ExtractorT2.POS)]; for(Entry<String,Integer> e : pipe.mf.getFeatureSet().get(ExtractorT2.POS).entrySet()) pipe.types[e.getValue()] = e.getKey(); DB.println("Loading data finished. "); } catch(Exception e) { e.printStackTrace(); } }
@Override protected Tagger produceResource(URL aUrl) throws IOException { File modelFile = ResourceUtils.getUrlAsFile(aUrl, true); String[] args = { "-model", modelFile.getPath() }; Options option = new Options(args); Tagger tagger = new Tagger(option); // create a POSTagger HashMap<String, HashMap<String, Integer>> featureSet = tagger.mf.getFeatureSet(); SingletonTagset posTags = new SingletonTagset(POS.class, getResourceMetaData() .getProperty("pos.tagset")); HashMap<String, Integer> posTagFeatures = featureSet.get("POS"); posTags.addAll(posTagFeatures.keySet()); posTags.removeAll(asList("<None>", "<root-POS>")); addTagset(posTags); if (printTagSet) { getContext().getLogger().log(INFO, getTagset().toString()); } return tagger; } };
System.out.println(); types= mf.reverse(mf.getFeatureSet().get(POS)); return is;
String wds[] = mf.reverse(this.pipe.mf.getFeatureSet().get(ExtractorT2.WORD));