📄 dependencypipe2o.java
字号:
} } out.writeInt(-3); for(FeatureVector curr = inst.fv; curr.next != null; curr = curr.next) out.writeInt(curr.index); out.writeInt(-4); out.writeObject(inst.sentence); out.writeInt(-5); out.writeObject(inst.pos); out.writeInt(-6); out.writeObject(inst.labs); out.writeInt(-7); out.writeObject(inst.actParseTree); out.writeInt(-1); out.reset(); } catch (IOException e) {} } public DependencyInstance getFeatureVector(ObjectInputStream in, DependencyInstance inst, FeatureVector[][][] fvs, double[][][] probs, FeatureVector[][][] fvs_trips, double[][][] probs_trips, FeatureVector[][][] fvs_sibs, double[][][] probs_sibs, FeatureVector[][][][] nt_fvs, double[][][][] nt_probs, Parameters params) throws IOException { int length = inst.length; // Get production crap. for(int w1 = 0; w1 < length; w1++) { for(int w2 = w1+1; w2 < length; w2++) { for(int ph = 0; ph < 2; ph++) { FeatureVector prodFV = new FeatureVector(-1,-1.0,null); int indx = in.readInt(); while(indx != -2) { prodFV = new FeatureVector(indx,1.0,prodFV); indx = in.readInt(); } double prodProb = params.getScore(prodFV); fvs[w1][w2][ph] = prodFV; probs[w1][w2][ph] = prodProb; } } } int last = in.readInt(); if(last != -3) { System.out.println("Error reading file."); System.exit(0); } if(labeled) { for(int w1 = 0; w1 < length; w1++) { for(int t = 0; t < types.length; t++) { String type = types[t]; for(int ph = 0; ph < 2; ph++) { for(int ch = 0; ch < 2; ch++) { FeatureVector prodFV = new FeatureVector(-1,-1.0,null); int indx = in.readInt(); while(indx != -2) { prodFV = new FeatureVector(indx,1.0,prodFV); indx = in.readInt(); } double nt_prob = params.getScore(prodFV); nt_fvs[w1][t][ph][ch] = prodFV; nt_probs[w1][t][ph][ch] = nt_prob; } } } } last = in.readInt(); if(last != -3) { System.out.println("Error reading file."); System.exit(0); } } for(int w1 = 0; w1 < length; w1++) { for(int w2 = w1; w2 < length; w2++) { for(int w3 = w2+1; w3 < length; w3++) { FeatureVector prodFV = new FeatureVector(-1,-1.0,null); int indx = in.readInt(); while(indx != -2) { prodFV = new FeatureVector(indx,1.0,prodFV); indx = in.readInt(); } double prodProb = params.getScore(prodFV); fvs_trips[w1][w2][w3] = prodFV; probs_trips[w1][w2][w3] = prodProb; } } for(int w2 = w1; w2 >= 0; w2--) { for(int w3 = w2-1; w3 >= 0; w3--) { FeatureVector prodFV = new FeatureVector(-1,-1.0,null); int indx = in.readInt(); while(indx != -2) { prodFV = new FeatureVector(indx,1.0,prodFV); indx = in.readInt(); } double prodProb = params.getScore(prodFV); fvs_trips[w1][w2][w3] = prodFV; probs_trips[w1][w2][w3] = prodProb; } } } last = in.readInt(); if(last != -3) { System.out.println("Error reading file."); System.exit(0); } for(int w1 = 0; w1 < length; w1++) { for(int w2 = 0; w2 < length; w2++) { for(int wh = 0; wh < 2; wh++) { if(w1 != w2) { FeatureVector prodFV = new FeatureVector(-1,-1.0,null); int indx = in.readInt(); while(indx != -2) { prodFV = new FeatureVector(indx,1.0,prodFV); indx = in.readInt(); } double prodProb = params.getScore(prodFV); fvs_sibs[w1][w2][wh] = prodFV; probs_sibs[w1][w2][wh] = prodProb; } } } } last = in.readInt(); if(last != -3) { System.out.println("Error reading file."); System.exit(0); } FeatureVector nfv = new FeatureVector(-1,-1.0,null); int next = in.readInt(); while(next != -4) { nfv = new FeatureVector(next,1.0,nfv); next = in.readInt(); } String[] toks = null; String[] pos = null; String[] labs = null; String actParseTree = null; try { toks = (String[])in.readObject(); next = in.readInt(); pos = (String[])in.readObject(); next = in.readInt(); labs = (String[])in.readObject(); next = in.readInt(); actParseTree = (String)in.readObject(); next = in.readInt(); } catch(ClassNotFoundException e) { System.out.println("Error reading file."); System.exit(0); } if(next != -1) { System.out.println("Error reading file."); System.exit(0); } DependencyInstance pti = new DependencyInstance(toks,pos,labs,nfv); pti.actParseTree = actParseTree; return pti; } public void getFeatureVector(DependencyInstance inst, FeatureVector[][][] fvs, double[][][] probs, FeatureVector[][][] fvs_trips, double[][][] probs_trips, FeatureVector[][][] fvs_sibs, double[][][] probs_sibs, FeatureVector[][][][] nt_fvs, double[][][][] nt_probs, Parameters params) { String[] toks = inst.sentence; String[] pos = inst.pos; String[] labs = inst.labs; String[] posA = new String[pos.length]; for(int i = 0; i < pos.length; i++) { posA[i] = pos[i].substring(0,1); } // Get production crap. for(int w1 = 0; w1 < toks.length; w1++) { for(int w2 = w1+1; w2 < toks.length; w2++) { for(int ph = 0; ph < 2; ph++) { boolean attR = ph == 0 ? true : false; int childInt = attR ? w2 : w1; int parInt = attR ? w1 : w2; FeatureVector prodFV = createFeatureVector(toks,pos,posA,w1,w2,attR, new FeatureVector(-1,-1.0,null)); double prodProb = params.getScore(prodFV); fvs[w1][w2][ph] = prodFV; probs[w1][w2][ph] = prodProb; } } } if(labeled) { for(int w1 = 0; w1 < toks.length; w1++) { for(int t = 0; t < types.length; t++) { String type = types[t]; for(int ph = 0; ph < 2; ph++) { boolean attR = ph == 0 ? true : false; for(int ch = 0; ch < 2; ch++) { boolean child = ch == 0 ? true : false; FeatureVector prodFV = createFeatureVector(toks,pos,posA,w1, type,attR,child, new FeatureVector(-1,-1.0,null)); double nt_prob = params.getScore(prodFV); nt_fvs[w1][t][ph][ch] = prodFV; nt_probs[w1][t][ph][ch] = nt_prob; } } } } } for(int w1 = 0; w1 < toks.length; w1++) { for(int w2 = w1; w2 < toks.length; w2++) { for(int w3 = w2+1; w3 < toks.length; w3++) { FeatureVector prodFV = createFeatureVector(toks,pos,posA,w1,w2,w3, new FeatureVector(-1,-1.0,null)); double prodProb = params.getScore(prodFV); fvs_trips[w1][w2][w3] = prodFV; probs_trips[w1][w2][w3] = prodProb; } } for(int w2 = w1; w2 >= 0; w2--) { for(int w3 = w2-1; w3 >= 0; w3--) { FeatureVector prodFV = createFeatureVector(toks,pos,posA,w1,w2,w3, new FeatureVector(-1,-1.0,null)); double prodProb = params.getScore(prodFV); fvs_trips[w1][w2][w3] = prodFV; probs_trips[w1][w2][w3] = prodProb; } } } for(int w1 = 0; w1 < toks.length; w1++) { for(int w2 = 0; w2 < toks.length; w2++) { for(int wh = 0; wh < 2; wh++) { if(w1 != w2) { FeatureVector prodFV = createFeatureVectorSib(toks,pos,w1,w2,wh == 0, new FeatureVector(-1,-1.0,null)); double prodProb = params.getScore(prodFV); fvs_sibs[w1][w2][wh] = prodFV; probs_sibs[w1][w2][wh] = prodProb; } } } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -