id
stringlengths
36
36
text
stringlengths
1
1.25M
4062adea-daff-4787-9fbe-801d7335c303
public void mouseMoved(MouseEvent e) {}
28f43c9f-c77e-421d-899c-d90d03f2a1d6
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
091c201d-fa3e-42a2-be0c-b13798c7abae
public Raypath(Point A, Point B, Point C) { this.A = A; this.B = B; this.C = C; }
a414963b-8584-442a-b557-c2722ec71fc4
public void setA(Point A) { this.A = A; }
1b95e68d-dde3-49fe-ad57-56d847c207e4
public void setB(Point B) { this.B = B; }
8e87a89a-29c6-4a1d-a0bb-a2aa4b69059a
public void setC(Point C) { this.C = C; }
ba3e3937-c0b8-4f0f-a5f9-c8e9ec3029ce
public Point getA() { return A; }
f9d34926-f8c9-4d8c-8f0c-65af4e03a62f
public Point getB() { return B; }
3cf742b9-b3dc-4261-8a8c-743ba53483bc
public Point getC() { return C; }
9a44a821-ea94-4ae2-a383-d8c007289de0
public Point getReceiver() { return Receiver; }
db4a2dd5-c79e-491d-b985-4f43abe8ffb4
public Point getSource() { return Source; }
fc48d429-f888-48d7-beeb-3f33aabf27b8
public FresnelVolume (MatriksKecepatan _MK) { // TO DO : bikin MK, Source, Receiver supaya jadi array MK = _MK; FMK = new MatriksKecepatan[10]; for (int i=0; i<FMK.length; i++) { // FMK[i] = new MatriksKecepatan(96,96); FMK[i] = _MK; } // FMK[0] = _MK; Point p = new Point(MK.getP()/2, MK.getL()/2); // velo = 1000; // f = 500; // makeEllipse (1,new Point(40, 20),new Point(50, 70)); makeEllipse (0,new Point(20, 20),new Point(70, 70)); hitungRataMK(); for (int i=0;i<RataMK.getP();i++){ for(int j=0;j<RataMK.getL();j++){ int idx = i*RataMK.getL()+j; System.out.print( RataMK.data[i][j]+" "); } System.out.println(""); } // --- END 1 --- System.out.println("Nilai Min : "+RataMK.getminv()); System.out.println("Nilai Max : "+RataMK.getmaxv()); System.out.println("P : "+RataMK.getP()); System.out.println("L : "+RataMK.getL()); }
ae556cd7-16b9-4547-adb9-1b03a3c1765e
private void makeEllipse (int iFMK, Point p1, Point p2) { Source = new Point(p1); Receiver = new Point(p2); // int r = MK.getP()/2; // double sdt = Math.toRadians(90.0); // int dx = (int)((float)r*Math.cos(sdt)); // int dy = (int)((float)r*Math.sin(sdt)); // Source = new Point(p.x - dx, p.y - dy); // Receiver = new Point(p.x + dx, p.y + dy); System.out.println(Source.x+" "+Source.y); System.out.println(Receiver.x+" "+Receiver.y); arraySP = new float[MK.getL()*MK.getP()]; arrayRP = new float[MK.getL()*MK.getP()]; arrayTCal = new float[MK.getL()*MK.getP()]; deltaT = new float[MK.getL()*MK.getP()]; deltaSi = new float[MK.getL()*MK.getP()]; sigma = new float[MK.getL()*MK.getP()]; deltaSiRata = new float[MK.getL()*MK.getP()]; slowness = new float[MK.getL()*MK.getP()]; slownessAkhir = new float[MK.getL()*MK.getP()]; slownessAkhirRata = new float[MK.getL()*MK.getP()]; kecepatanModel = new float[MK.getL()*MK.getP()]; kecepatanModelRata = new float[MK.getL()*MK.getP()]; bobotij = new float[MK.getL()*MK.getP()][]; garis = new LinkedList(); // Loop 1 : Hitung distance dan time for (int i=0;i<MK.getP();i++){ for(int j=0;j<MK.getL();j++){ int idx = i*MK.getL()+j; float velo_now = Float.valueOf(MK.data[j][i]); if (isDalamEllips(i,j,Source,Receiver)) { // kalo dalam ellips, hitung arraySP[idx] = distance(Source,new Point(i,j))/velo_now; arrayRP[idx] = distance(Receiver,new Point(i,j))/velo_now; arrayTCal[idx] = hitungArrayTCal(arraySP[idx], arrayRP[idx]); tobs = distance(Source,Receiver)/velo_now; deltaT[idx] = hitungDeltaT(arrayTCal[idx], tobs); } else { // kalo ga, 0 arraySP[idx] = 0/velo_now; arrayRP[idx] = 0/velo_now; arrayTCal[idx] = 0; deltaT[idx] = 0; } slowness[idx] = 1f/velo_now; } } // --- END 1 --- // Loop 2 for (int i=0;i<MK.getP();i++){ for(int j=0;j<MK.getL();j++){ int jumRayPerSel = 0; int idx = i*MK.getL()+j; bobotij[idx] = new float[MK.getL()*MK.getP()]; Point Persegi = new Point(i,j); garis.add(new Raypath(Source,Persegi,Receiver)); float totalw = 0f; // Loop 2.1 : Cari jumRayPerSel, bobot, totalw for (int k=0;k<MK.getP();k++){ for(int l=0;l<MK.getL();l++){ int jdx = k*MK.getL()+l; Point P = new Point(k,l); if (isDalamEllips(i,j,Source,Receiver)) { if (IsKotakIntersect(Source,P,Persegi)||IsKotakIntersect(Receiver,P,Persegi)) { jumRayPerSel++; } bobotij[idx][jdx] = (hitungBobotij(deltaT[jdx])); } else { bobotij[idx][jdx] = 0; } totalw += bobotij[idx][jdx]; } } // --- END 2.1 --- // Loop 2.2 : Cari sigma float sik = 1/velo; for (int k=0;k<MK.getP();k++){ for(int l=0;l<MK.getL();l++){ int jdx = k*MK.getL()+l; Point P = new Point(k,l); if (isDalamEllips(i,j,Source,Receiver) && IsKotakIntersect(Source,P,Persegi)||IsKotakIntersect(Receiver,P,Persegi)) { sigma[jdx] = deltaT[jdx]/arrayTCal[jdx]*bobotij[idx][jdx]/totalw; if (Double.isNaN(sigma[jdx])) { sigma[jdx] = 0; } } else { sigma[jdx] = 0; } } } // --- END 2.2 --- float totalsigma=0f; for (int k=0;k<MK.getP();k++){ for(int l=0;l<MK.getL();l++){ int jdx = k*MK.getL()+l; if (isDalamEllips(i,j,Source,Receiver)) totalsigma += sigma[jdx]; else totalsigma +=0; } } // --- END 2.2 --- if (isDalamEllips(i,j,Source,Receiver)) { deltaSi[idx] = totalsigma*slowness[idx]; // deltaSi[idx] = (deltaSi[idx]>600)? 600 : deltaSi[idx]; deltaSiRata[idx] = deltaSi[idx]/jumRayPerSel; slownessAkhir[idx] = slowness[idx] + deltaSi[idx]; slownessAkhirRata[idx] = slowness[idx] + deltaSiRata[idx]; kecepatanModel[idx] = 1/slownessAkhir[idx]; kecepatanModelRata[idx] = 1/slownessAkhirRata[idx]; } else { deltaSi[idx] = 0; deltaSiRata[idx] = 0; slownessAkhir[idx] = 0; slownessAkhirRata[idx] = 0; kecepatanModel[idx] = 0; kecepatanModelRata[idx] = 0; } FMK[iFMK].data[j][i]=Float.toString((float)kecepatanModelRata[idx]); } } // --- END 2 --- FMK[iFMK].setMaxMinVal(); }
e290c321-32a5-4820-8043-501d69a95a1b
private float hitungArrayTCal (float SP, float RP) { return SP + RP; }
fd94338c-b8b9-469f-8dc2-eb782e28f9e3
private float hitungDeltaT (float TCal, float tobs) { return Math.abs(tobs - TCal); }
9eeb8687-4e6c-49e1-8363-3de6e675ebfe
private float hitungBobotij (float deltaT) { if (deltaT >= (f/2)) return 0; else return 1-2*f*deltaT; }
38a4206f-c777-46c5-b867-51326413fd2b
private boolean isDalamEllips (int i, int j, Point P, Point Q) { Point pusat = new Point(Math.abs(P.y+Q.y)/2, Math.abs(P.x+Q.x)/2); float tinggiEllips = 40f; float PQ = distance(P,Q); float a = PQ/2; float b = tinggiEllips/2; float sina = (Q.y-P.y) / PQ; float cosa = (Q.x-P.x) / PQ; float kiri = (j-pusat.x)*cosa + (i-pusat.y)*sina; float kanan = (j-pusat.x)*sina - (i-pusat.y)*cosa; // System.out.println(pusat.x+" "+pusat.y); // float kiri = (j-pusat.x); // float kanan = (i-pusat.y); return Math.pow((kiri/b),2) + Math.pow((kanan/a),2)<1; }
082bbc10-19ae-461c-8d95-698e920754a2
private float distance(Point P, Point Q) { return (float)Math.sqrt((P.x-Q.x)*(P.x-Q.x) + (P.y-Q.y)*(P.y-Q.y)); }
e53698c0-8e85-4433-a28e-8443da3a978b
private boolean IsIntersecting(Point a, Point b, Point c, Point d) { float denominator = ((b.x - a.x) * (d.y - c.y)) - ((b.y - a.y) * (d.x - c.x)); float numerator1 = ((a.y - c.y) * (d.x - c.x)) - ((a.x - c.x) * (d.y - c.y)); float numerator2 = ((a.y - c.y) * (b.x - a.x)) - ((a.x - c.x) * (b.y - a.y)); // Detect coincident lines (has a problem, read below) if (denominator == 0) return numerator1 == 0 && numerator2 == 0; float r = numerator1 / denominator; float s = numerator2 / denominator; return (r >= 0 && r <= 1) && (s >= 0 && s <= 1); }
a16a9c64-6ff2-4e0d-b659-0a41b516e140
private boolean IsKotakIntersect(Point O, Point O2, Point Persegi) { Point P = new Point(Persegi.x,Persegi.y); Point P2 = new Point(Persegi.x,Persegi.y+1); Point P3 = new Point(Persegi.x+1,Persegi.y); Point P4 = new Point(Persegi.x+1,Persegi.y+1); return (IsIntersecting(O,O2,P,P2) ||IsIntersecting(O,O2,P2,P3) ||IsIntersecting(O,O2,P3,P4) ||IsIntersecting(O,O2,P4,P)); }
f7a2a34e-6a9d-4966-8906-0b6bda05a8c2
public void hitungLSR(){ // lSR = 1/velo; }
4180b6d4-d776-4d79-94e6-184613a9a0b8
public void hitungDeltaSi(){ // bobotRata[] // // for int(i=1;i<MK.getL()*MK.getP();i++){ // deltaSi[i]= (1/jmlRayPerSel[i-1]) + jmlRayPerSel[i-1] * (deltaT[i-1]/arrayTCal) * (bobotRata[i-1]/bobotij[i-1]); // }//end for }
6d83414c-a974-40a2-91cc-03fc1d4336c0
public void hitungBobotRata(){ }
799221ca-6535-49d8-a76a-85d10581c4f3
public void hitungRataMK () { RataMK = new MatriksKecepatan(FMK[0]); for (int i=0;i<MK.getP();i++){ for(int j=0;j<MK.getL();j++){ float total = 0f; for (int k=0; k<FMK.length; k++) { total += Float.valueOf(FMK[k].data[i][j]); } total /= FMK.length; RataMK.data[i][j] = String.valueOf(total); } } RataMK.setMaxMinVal(); }
317b4e34-62d3-419c-962e-ad68e84cfd21
public Penggambar () { MatriksKecepatan MK = new MatriksKecepatan(); O = new Point(0,0); }
3f4de5fe-f2ef-4034-bc39-36467add9290
public Penggambar (MatriksKecepatan _mk) { MK = new MatriksKecepatan(); MK = _mk; MK.setMaxMinVal(); O = new Point(0,0); }
9c3e9e3c-0636-4bb1-9bb6-92938838b186
public void seto (int x, int y) {O.setLocation(x, y);}
2e2029ab-fe9a-4257-9970-109eb6a73a62
public int getox () {return (int)O.getX();}
1ed45826-82c8-4f76-b53f-4b77fe653a79
public int getoy () {return (int)O.getY();}
acce9b7f-8c0a-4d63-9adf-99aa6997131f
public void gesero (int x, int y) {O.setLocation(x+getox(), y+getoy());}
504f1176-2642-4161-9a08-71058c737b5e
public int getnx() { return MK.getP(); }
cc0990d3-c7c0-4782-afa8-cfda8d478fa7
public int getny() { return MK.getL(); }
514ced3f-d286-409a-9e53-daa1e06d6795
public void gambar_garis(GL gl, Point P, Point Q, Color C) { gl.glBegin (GL.GL_LINES); gl.glColor3f(C.getRed(), C.getGreen(), C.getBlue()); gl.glVertex3f( (float)P.getX(), (float)P.getY(), 0); gl.glVertex3f( (float)Q.getX(), (float)Q.getY(), 0); gl.glEnd(); }
83e55ff8-b30a-46af-8225-8891d2ea519a
private void gambar_kotakborder(GL gl, Point P, Color C, int lebarkotak) { gl.glBegin (GL.GL_LINES); Point Q = new Point(P); // kanan bawah Point R = new Point(P); // kanan atas Point S = new Point(P); // kiri atas Q.translate(0, lebarkotak); R.translate(lebarkotak, lebarkotak); S.translate(lebarkotak, 0); gambar_garis(gl,P,Q,C); gambar_garis(gl,Q,R,C); gambar_garis(gl,R,S,C); gambar_garis(gl,S,P,C); gl.glEnd(); }
a97c731d-636e-422c-9866-b537ac92ff69
private void gambar_kotakwarna(GL gl, Point P) { gl.glBegin(GL.GL_QUADS); Point Q = new Point(P); // kanan bawah Point R = new Point(P); // kanan atas Point S = new Point(P); // kiri atas Q.translate(0, 1); R.translate(1, 1); S.translate(1, 0); gl.glColor3f(0f, 1f, 1.0f); // blue gl.glVertex3f((float)P.getX(), (float)P.getY(), 0.0f); // kiri bawah gl.glColor3f(1f, 1f, 0.0f); // green gl.glVertex3f((float)Q.getX(), (float)Q.getY(), 0.0f); // kanan bawah gl.glColor3f(1.0f, 0f, 0.0f); // red gl.glVertex3f((float)R.getX(), (float)R.getY(), 0.0f); // kanan atas gl.glColor3f(0.5f, 0.5f, 1.0f); // light blue gl.glVertex3f((float)S.getX(), (float)S.getY(), 0.0f); // kiri atas gl.glEnd(); }
98609608-1910-4b2e-9793-3ec1d210a91f
private void gambar_kotakrandom(GL gl, Point P) { gl.glBegin(GL.GL_QUADS); Point Q = new Point(P); // kanan bawah Point R = new Point(P); // kanan atas Point S = new Point(P); // kiri atas Q.translate(0, 1); R.translate(1, 1); S.translate(1, 0); float c1 = (float)Math.random(); float c2 = (float)Math.random(); float c3 = (float)Math.random(); gl.glColor3f(c1, c2, c3); gl.glVertex3f((float)P.getX(), (float)P.getY(), 0.0f); // kiri bawah gl.glVertex3f((float)Q.getX(), (float)Q.getY(), 0.0f); // kanan bawah gl.glVertex3f((float)R.getX(), (float)R.getY(), 0.0f); // kanan atas gl.glVertex3f((float)S.getX(), (float)S.getY(), 0.0f); // kiri atas gl.glEnd(); }
f8c6c7a8-4257-4b0f-9ddd-5b13c72e1cdd
private void gambar_kotak(GL gl, Point P, float val) { float pv = ((float)val-(float)MK.getminv()+1f)/((float)MK.getmaxv()-(float)MK.getminv()+1f); Color c = new Color ((int)((float)pv*(float)255)); // cr = c.getRed()/(float)255; // cg = c.getGreen()/(float)255; // cb = c.getBlue()/(float)255; float cr = (float)1; float cg = (float)1; float cb = (float)1; float pv6 = pv*(float)6; if (pv6 <= 1) { // ungu - biru cr = (float)1-pv6; cg = (float)0; cb = (float)1; } else if (pv6 <= 2) { // biru - biru m. cr = (float)0; cg = pv6-(float)1; cb = (float)1; } else if (pv6 <= 3) { // biru m. - hijau cr = (float)0; cg = (float)1; cb = (float)3-pv6; } else if (pv6 <= 4) { // hijau - kuning cr = pv6-(float)3; cg = (float)1; cb = (float)0; } else if (pv6 <= 5) { // kuning - jingga cr = (float)1; cg = ((float)5-pv6)/((float)2) + (float)0.5; cb = (float)0; } else if (pv6 <= 6) { // jingga - merah cr = (float)1; cg = ((float)6-pv6)/((float)2); cb = (float)0; } // int RGB = Color.HSBtoRGB(1-pv, 1, 1); // cr = ((RGB >> 16) & 0xFF)/255.0f; // cg = ((RGB >> 8)& 0xFF) / 255.0f; // cb = ((RGB) & 0xFF) / 255.0f; gl.glBegin(GL.GL_QUADS); Point Q = new Point(P); // kanan bawah Point R = new Point(P); // kanan atas Point S = new Point(P); // kiri atas Q.translate(0, 1); R.translate(1, 1); S.translate(1, 0); gl.glColor3f(cr, cg, cb); gl.glVertex3f((float)P.getX(), (float)P.getY(), 0.0f); // kiri bawah gl.glVertex3f((float)Q.getX(), (float)Q.getY(), 0.0f); // kanan bawah gl.glVertex3f((float)R.getX(), (float)R.getY(), 0.0f); // kanan atas gl.glVertex3f((float)S.getX(), (float)S.getY(), 0.0f); // kiri atas gl.glEnd(); }
e6d22d25-3f24-4cc4-bcfc-3ab8b2798701
public void gambar_mk_kotakwarna(GL gl) { for (int i= getox(); i<MK.getP()+getox(); i++) { for (int j= getoy(); j<MK.getL()+getoy(); j++) { Point T = new Point(i,j); gambar_kotak(gl, T, MK.getFloatData(j-getoy(),i-getox())); } } }
2650334e-38d5-4b95-980b-a681f178ae7d
public void gambar_mk_border(GL gl, int lebarkotak) { Color CBorder = new Color((float)0, (float)0, (float)0); for (int i= getox(); i<(MK.getP()+getox())/lebarkotak; i++) { for (int j= getoy(); j<(MK.getL()+getoy())/lebarkotak; j++) { Point T = new Point(i*lebarkotak, j*lebarkotak); gambar_kotakborder(gl, T, CBorder, lebarkotak); } } }
a8d62ff9-7f11-48d2-88d3-dabee2ab7c44
public void gambar_mk_kotakrandom(GL gl) { Color CBorder = new Color((float)0, (float)0, (float)0); for (int i= getox(); i<MK.getP()+getox(); i++) { for (int j= getoy(); j<MK.getL()+getoy(); j++) { Point T = new Point(i,j); gambar_kotakrandom(gl, T); } } }
aaca1cef-365a-49be-8eb6-21eacb802673
public void gambar_axor(GL gl, GLUT glut, Camera K) { Point P = new Point(0,150); Point Q = new Point(150,0); Point R = new Point(0,-30); Point S = new Point(-30,0); Color CBorder = new Color((float)0, (float)0, (float)0); gambar_garis(gl,P,R,CBorder); gambar_garis(gl,Q,S,CBorder); // --- angka --- int iii = 0; int mx = (int)(-5.0*(K.getJarak()/150.0)); int my = (int)(-5.0*(K.getJarak()/150.0)); gambarTeks (gl, glut, Integer.toString(iii), Color.black, new Point(mx,my)); for (iii = 1; iii<=15; iii++) { mx = (int)(-5.0*(K.getJarak()/150.0)); my = (int)(-5.0*(K.getJarak()/150.0)); if (iii>9) mx = (int)(-6.0*(K.getJarak()/150.0)); gambarTeks (gl, glut, Integer.toString(iii), Color.black, new Point(mx, iii*8)); gambarTeks (gl, glut, Integer.toString(iii), Color.black, new Point(iii*8, my)); } }
96cc3ec2-1ac8-4117-b3d9-761ba4e85dd9
public void gambarTeks( GL gl, GLUT glut, String teks, Color C, Point P) { gl.glColor3f(C.getRed(), C.getGreen(), C.getBlue()); gl.glRasterPos3d(P.getX(), P.getY(), 0); glut.glutBitmapString(glut.BITMAP_HELVETICA_12, teks ); }
783bf46e-7e4b-4af2-9bf1-6a51bcedc6f3
public void test_pelangi () { for (int i=0;i<MK.getP();i++){ for(int j=0;j<MK.getL();j++){ MK.data[i][j]=Integer.toString(i+j); } } MK.setMaxMinVal(); }
b30e33de-b3cc-4f1f-8db9-d63f387de12e
public void tes() { FresnelVolume F = new FresnelVolume(MK); OMK = F.MK; MK = F.RataMK; // garis = F.garis; //Raypath(F.getReceiver(), new Point(40,40), F.getSource()); }
438cce8b-2385-4be8-aa96-6316ce3d9c41
public void gambar_ray(GL gl) { for (int i=0; i<garis.size(); i++) { Raypath temp = garis.get(i); gambar_garis(gl,temp.getA(),temp.getB(), Color.BLACK); gambar_garis(gl,temp.getB(),temp.getC(), Color.BLACK); } }
7f69b97a-c132-45da-8632-29afda16bf1e
public void identify() { System.out.println("SB Daniel (RamaDSB Creada)"); }
faed5c4b-f8f4-4373-8a22-5e34a3f96c31
public void identify() { System.out.println("MA Alvaro"); }
ace24519-8cc4-4178-9b9b-e9503e983101
public void identify() { System.out.println("Empresa AMA2"); }
43045467-2f80-4dbe-84a1-98adcf9fd922
public static void main(String[] args) { // AccessControl guardian = new AccessControl(); // if (guardian.hasAccess()) { // Right workerAtRight = new Right(); // Left workerAtLeft = new Left(); Company company = new Company(); DSB dsb = new DSB(); AMA ama=new AMA(); System.out.println("=================================================="); System.out.println(" Product Developed by "); System.out.println(""); company.identify(); dsb.identify(); ama.identify(); System.out.println(""); System.out.println(" Credits To "); System.out.println(""); // workerAtLeft.identify(); // workerAtRight.identify(); System.out.println("=================================================="); // } else { // System.out.println("You do not have access to this application"); // }// if } // main
cccbe50f-56be-4bbe-a0cd-5d579d016fb9
public static void main(String[] args) throws IOException { if (args.length < 1) { System.err.println("Usage: java " + TestMMSeg.class.getSimpleName() + " <input> [output]"); System.exit(1); } InputStream inputStream = new FileInputStream(args[0]); OutputStream outputStream; if (args.length >= 2) { outputStream = new FileOutputStream(args[1]); } else { outputStream = System.out; } BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); Writer writer = new OutputStreamWriter(outputStream); MMSeg mmSeg = new MMSeg(); Date startTime = new Date(); int lineCount = 0; int tokenCount = 0; try { String line = reader.readLine(); while (line != null) { lineCount++; mmSeg.reset(new StringReader(line)); StringBuffer buffer = new StringBuffer(); Token token = mmSeg.next(); while (token != null) { tokenCount++; if (buffer.length() > 0) { buffer.append(" "); } buffer.append(token.getText()); token = mmSeg.next(); } buffer.append("\n"); writer.write(buffer.toString()); line = reader.readLine(); } } finally { reader.close(); writer.close(); } Date endTime = new Date(); double seconds = (double) (endTime.getTime() - startTime.getTime()) / 1000; System.out.println("Time spent: " + DECIMAL_FORMAT.format(seconds) + " seconds"); System.out.println("Lines : " + lineCount); System.out.println("Tokens : " + tokenCount); System.out.println("Lines/Sec : " + DECIMAL_FORMAT.format(lineCount / seconds)); System.out.println("Tokens/Sec: " + DECIMAL_FORMAT.format(tokenCount / seconds)); }
53851e20-6096-4cca-8c47-77db9be9fb65
public MMSegData() throws IOException { dictionary = new MMSegDictionary(); }
40ac8d8d-492a-4add-9c83-429a8e7af670
public List<Rule> getRules() { return rules; }
76bfa162-d955-4156-8603-f3fe7abfd936
public MMSegDictionary getDictionary() { return dictionary; }
a72433f4-dcfd-41d0-86d9-10b0d8aa74cf
@Override protected TokenStreamComponents createComponents(String fieldName, Reader reader) { StandardTokenizer t = new StandardTokenizer(Version.LUCENE_43, reader); return new TokenStreamComponents(t, new LowerCaseFilter(Version.LUCENE_43, t)); }
7c5c7fe5-6e00-4e25-ab98-39600619042d
public void reset(MMSegData mmSegData, Part part) { rules = mmSegData.getRules(); dictionary = mmSegData.getDictionary(); this.part = part; text = part.getText(); maxWordCache.clear(); tokens.clear(); currentIndex = 0; seg(); }
c02a1abe-f4cb-45d0-b747-6d355869cd38
public boolean hasMoreTokens() { return tokens != null && !tokens.isEmpty() && tokens.size() > currentIndex; }
9bb220f8-2e96-45eb-a09e-d22d372ace1c
public Token takeNextToken() { if (hasMoreTokens()) { return tokens.get(currentIndex++); } else { return null; } }
d5a81d0f-ba2e-4e00-9aa5-8336304242a8
private void seg() { if (part.getType() == PartType.NON_CHINESE) { try { TokenStream tokenStream = analyzer.tokenStream(null, new CharArrayReader(text)); tokenStream.reset(); CharTermAttribute termAttribute = tokenStream.getAttribute(CharTermAttribute.class); OffsetAttribute offsetAttribute = tokenStream.getAttribute(OffsetAttribute.class); while (tokenStream.incrementToken()) { tokens.add(new Token(termAttribute.toString(), offsetAttribute.startOffset(), offsetAttribute.endOffset())); } } catch (IOException e) { throw new RuntimeException("Unable to tokenize text", e); } } else { int start = 0; while (start < text.length) { String token = maxNWords(start, N); tokens.add(new Token(token, start, start + token.length())); start += token.length(); } } }
62101373-a5cf-463a-bf35-50b842a6ac4b
private String maxNWords(int start, int n) { Node[] ends = new Node[n]; MaxNResult result = new MaxNResult(start, n); maxNWordsRec(start, ends, 0, n, result); return String.valueOf(text, start, result.ends[0].wordLength()); }
48a6f48a-2d4b-4fd1-a586-a577e40939fa
private void maxNWordsRec(int start, Node[] ends, int i, int n, MaxNResult result) { if (start == text.length) { for (int j = i; j < n; j++) { ends[j] = null; } setResult(start, ends, result); } else if (i == n - 1) { Node end = maxWord(start); ends[i] = end; setResult(start, ends, result); } else { Node node = dictionary.newNode(text[start]); ends[i] = node; maxNWordsRec(start + 1, ends, i + 1, n, result); for (int j = start + 1; node != null && j < text.length; j++) { Node next = node.get(text[j]); if (next != null && next.exists()) { ends[i] = next; maxNWordsRec(j + 1, ends, i + 1, n, result); } node = next; } } }
f324fdf3-5fcc-42bd-97a4-2e61979fd45a
private Node maxWord(int start) { Node result = maxWordCache.get(start); if (result != null) { return result; } Node node = dictionary.newNode(text[start]); Node maxNode = node; for (int i = start; node != null && i < text.length; i++) { Node next = node.get(text[i]); if (next != null && next.exists()) { maxNode = node; } node = next; } maxWordCache.put(start, maxNode); return maxNode; }
151dd675-6f42-4bbb-b7e9-1c122b9dde99
private void setResult(int start, Node[] ends, MaxNResult result) { int chunkLength = totalLength(ends); if (chunkLength > result.maxChunkLength || chunkLength == result.maxChunkLength && checkRules(start, ends, result.ends)) { result.maxChunkLength = chunkLength; System.arraycopy(ends, 0, result.ends, 0, ends.length); } }
8f6149b2-dd08-4071-9235-91c63c1baa35
private int totalLength(Node[] ends) { int length = 0; for (Node end : ends) { if (end == null) { break; } length += end.wordLength(); } return length; }
1b8e1f2b-b9d0-48b8-9f62-df6a30a65715
private boolean checkRules(int start, Node[] ends1, Node[] ends2) { if (rules != null) { for (Rule rule : rules) { int result = rule.compare(dictionary, text, start, ends1, ends2); if (result < 0) { return true; } else if (result > 0) { return false; } } } return false; }
27152977-343d-45e0-afbb-ce3874d48844
public MaxNResult(int start, int n) { ends = new Node[n]; }
94ac1b27-97b9-43fb-97fe-3c06bb4439fe
public MMSeg() throws IOException { this(new MMSegData()); }
b4411604-67f5-448f-8d4b-f3254957e704
public MMSeg(MMSegData mmSegData) { this.mmSegData = mmSegData; }
ce438efe-8b45-49c4-8c50-00ba4aa91792
public void reset(Reader reader) { this.reader = new PushbackReader(reader); }
3234f78e-fa34-4d31-b812-8aff7f9ae91b
public Token next() throws IOException { if (chunks == null || !chunks.hasMoreTokens()) { Part part = nextPart(); if (part == null) { return null; } chunks.reset(mmSegData, part); } return chunks.takeNextToken(); }
523b0e71-4047-4d96-aec5-1f017fc11134
public Part nextPart() throws IOException { int nextChar = reader.read(); if (nextChar < 0) { return null; } Part part = new Part(currentIndex); do { if (!part.append(nextChar)) { reader.unread(nextChar); break; } currentIndex++; nextChar = reader.read(); } while (nextChar >= 0); return part; }
9ab45039-3ebc-4bb7-9651-b5fc749e5cb0
public MMSegDictionary() throws IOException { this(new InputStreamReader(MMSegDictionary.class.getClassLoader().getResourceAsStream(DEFAULT_WORDS_FILE)), new InputStreamReader(MMSegDictionary.class.getClassLoader().getResourceAsStream(WORD_FREQYENCY_FILE)), true); }
0ec11350-d5d1-4889-8a24-0e99dd18eaf3
private MMSegDictionary(Reader wordsReader, Reader wordFrequencyReader, boolean close) throws IOException { try { loadDictionary(wordsReader); loadDictionary(wordFrequencyReader); } finally { if (close) { wordsReader.close(); wordFrequencyReader.close(); } } }
97e896ea-5349-41a9-bb0b-f2e4035451b4
public Node newNode(char ch) { return tree.seek(ch, true); }
f721a684-b0de-4033-b105-89026d8955ad
public Node newNode(char[] word) { return tree.seek(word, 0, -1, true); }
97d6d74a-9f16-4d3c-8224-38e0c17ec086
public void loadDictionary(Reader reader) throws IOException { BufferedReader bufferedReader = new BufferedReader(reader); String line = bufferedReader.readLine(); while (line != null) { int commentStart = line.indexOf(COMMENT_PREFIX); if (commentStart >= 0) { line = line.substring(0, commentStart); } line = line.trim(); if (line.isEmpty()) { continue; } String[] parts = line.split(" "); Node node = newNode(parts[0].toCharArray()); if (parts.length > 1) { node.frequency = Long.parseLong(parts[1]); } line = bufferedReader.readLine(); } }
0cf34cb1-f9cd-4965-a0cd-6ac306215d26
public Node getTree() { return tree; }
63dce873-a8c4-4be7-85d8-28c14fdc7708
private Node(Node parent, char ch, int depth) { this.parent = parent; this.ch = ch; this.depth = depth; }
a02393c6-55c1-4747-a80c-19d7f478f2b5
public Node get(char ch) { return children.get(ch); }
13870a7c-115f-4e5f-89e3-40c2d9b0dd71
public Node parent() { return parent; }
6d1ccd8c-0595-486a-af39-92e4c6cb57b6
public char getChar() { return ch; }
80366826-d77d-40b9-af42-91736b63a0e7
public double weight() { return weight; }
20714f84-1d20-44aa-abc6-8e05f596a63e
public long frequency() { return frequency; }
ca9e912d-e194-40f9-a16e-94e5277249c2
public boolean exists() { return exists; }
909d0ee5-bd5e-4f5b-b19b-d4d67aee3a3e
public int wordLength() { return exists ? depth : -1; }
a78a2e79-31af-492e-8d5c-d767f3442421
public Node seek(char ch, boolean createNew) { Node child = children.get(ch); if (createNew) { if (child == null) { child = new Node(this, ch, depth + 1); children.put(ch, child); } child.exists = true; } return child; }
bc43bbe8-a0ec-454c-b62f-858c9ae023a7
public Node seek(char[] word, int start, int end, boolean createNew) { if (end >= 0 && start == end || end < 0 && start == word.length) { if (createNew) { exists = true; } return this; } char ch = word[start]; Node child = children.get(ch); if (child == null) { if (createNew) { child = new Node(this, ch, depth + 1); children.put(ch, child); } else { return null; } } return child.seek(word, start + 1, end, createNew); }
44eb8c3e-c2c6-474f-abc5-4f7b6544c12e
public String getWord() { StringBuffer buffer = new StringBuffer(depth); Node node = this; while (node.parent != null) { buffer.append(node.ch); node = node.parent; } return buffer.reverse().toString(); }
6c851609-2a29-42b9-8495-a40d5601dcab
@Override public String toString() { return getWord(); }
59212d07-c239-407a-84c8-e9dc3d80e6d1
@Override public int compare(MMSegDictionary dictionary, char[] text, int start, Node[] ends1, Node[] ends2) { return Long.compare(getTotalFrequency(dictionary, ends2), getTotalFrequency(dictionary, ends1)); }
fe371901-229a-43ea-aaee-75e5adc91b05
private long getTotalFrequency(MMSegDictionary dictionary, Node[] ends) { long totalFrequency = 0; for (Node end : ends) { if (end == null) { break; } totalFrequency += end.frequency(); } return totalFrequency; }
0447b4d6-b4b6-48a5-b870-5caf975f778f
public int compare(MMSegDictionary dictionary, char[] text, int start, Node[] ends1, Node[] ends2);
2c4b05cd-6a6a-41c8-969b-8144cce2e3d5
@Override public int compare(MMSegDictionary dictionary, char[] text, int start, Node[] ends1, Node[] ends2) { return Double.compare(variance(ends1), variance(ends2)); }
99d0f5d3-70dd-447c-8489-1be307591ce5
private double variance(Node[] ends) { int words = 0; int maxLength = 0; for (; words < ends.length && ends[words] != null; maxLength += ends[words].wordLength(), words++); double avgLength = (double) maxLength / words; double variance2 = 0.0; for (Node end : ends) { if (end == null) { break; } double difference = end.wordLength() - avgLength; variance2 += difference * difference; } return variance2; }
5a415ef0-c7d3-4a7e-86dd-0e8d8c601a77
@Override public int compare(MMSegDictionary dictionary, char[] text, int start, Node[] ends1, Node[] ends2) { return Integer.compare(getWordCount(ends1), getWordCount(ends2)); }
d0fd303b-6194-4e8e-96d4-60bad4564ed9
private int getWordCount(Node[] ends) { int size = ends.length; while (size > 0 && ends[size - 1] == null) { size--; } return size; }
5b18df5e-5f14-4865-89a2-9a917ebc51e4
public static CharType getCharType(int ch) { if (ch == '.') { return DOT; } if (Character.isWhitespace(ch)) { return WHITESPACE; } switch (Character.getType(ch)) { case Character.UPPERCASE_LETTER: case Character.LOWERCASE_LETTER: case Character.TITLECASE_LETTER: case Character.MODIFIER_LETTER: return LETTER; case Character.DECIMAL_DIGIT_NUMBER: case Character.LETTER_NUMBER: case Character.OTHER_NUMBER: return NUMBER; case Character.START_PUNCTUATION: case Character.END_PUNCTUATION: case Character.INITIAL_QUOTE_PUNCTUATION: case Character.FINAL_QUOTE_PUNCTUATION: case Character.DASH_PUNCTUATION: case Character.CONNECTOR_PUNCTUATION: case Character.OTHER_PUNCTUATION: return PUNCTUATION; default: if (ch < 128) { return OTHER_ASCII; } else { return OTHER; } } }
69255134-3b98-47bd-a03f-52661abce398
public Token(String text, int start, int end) { this.text = text; this.start = start; this.end = end; }
bedc3bfa-79ef-45a5-93d6-71ee273de5de
public String getText() { return text; }
13866d70-e208-41e3-8141-8368d23b8e51
public int getStart() { return start; }
08a37521-9fe4-4d94-a977-5c997362ab98
public int getEnd() { return end; }