Skip to content

Commit

Permalink
add default model
Browse files Browse the repository at this point in the history
  • Loading branch information
shin285 committed May 4, 2017
1 parent a68dbbb commit 906b2db
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 116 deletions.
Binary file removed models_full/irregular.model
Binary file not shown.
Binary file removed models_full/observation.model
Binary file not shown.
46 changes: 0 additions & 46 deletions models_full/pos.table

This file was deleted.

Binary file removed models_full/transition.model
Binary file not shown.
Binary file removed models_light/irregular.model
Binary file not shown.
Binary file removed models_light/observation.model
Binary file not shown.
46 changes: 0 additions & 46 deletions models_light/pos.table

This file was deleted.

Binary file removed models_light/transition.model
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kr.co.shineware.nlp.komoran.constant;

/**
* Created by shin285 on 2017. 5. 5..
*/
public enum DEFAULT_MODEL {
LIGHT, FULL
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class FILENAME {
public static final String OBSERVATION="observation.model";
public static final String TRANSITION="transition.model";
public static final String IRREGULAR_MODEL="irregular.model";
public static final String FULL_MODEL = "models_full";
public static final String LIGHT_MODEL = "models_light";
}
28 changes: 15 additions & 13 deletions src/main/java/kr/co/shineware/nlp/komoran/core/Komoran.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package kr.co.shineware.nlp.komoran.core;

import kr.co.shineware.ds.aho_corasick.FindContext;
import kr.co.shineware.nlp.komoran.constant.DEFAULT_MODEL;
import kr.co.shineware.nlp.komoran.constant.FILENAME;
import kr.co.shineware.nlp.komoran.constant.SCORE;
import kr.co.shineware.nlp.komoran.constant.SYMBOL;
Expand Down Expand Up @@ -52,30 +53,31 @@ public class Komoran implements Cloneable{
private Observation userDic;
private KoreanUnitParser unitParser;

// private Lattice lattice;


private HashMap<String, List<Pair<String, String>>> fwd;

// private String prevPos;
// private String prevMorph;
// private int prevBeginIdx;


public Komoran(String modelPath){
this.resources = new Resources();
this.load(modelPath);
this.unitParser = new KoreanUnitParser();
}

public Komoran(){
public Komoran(DEFAULT_MODEL modelType){

this.resources = new Resources();
this.resources.init();
InputStream posTableFile = this.getResourceStream("models_full"+File.separator+ FILENAME.POS_TABLE);
InputStream irrModelFile = this.getResourceStream("models_full"+File.separator+ FILENAME.IRREGULAR_MODEL);
InputStream observationFile = this.getResourceStream("models_full"+File.separator+ FILENAME.OBSERVATION);
InputStream transitionFile = this.getResourceStream("models_full"+File.separator+ FILENAME.TRANSITION);
String modelPath;
if(modelType == DEFAULT_MODEL.FULL){
modelPath = FILENAME.FULL_MODEL;
}else if(modelType == DEFAULT_MODEL.LIGHT){
modelPath = FILENAME.LIGHT_MODEL;
}else{
modelPath = FILENAME.FULL_MODEL;
}
InputStream posTableFile = this.getResourceStream(modelPath+File.separator+ FILENAME.POS_TABLE);
InputStream irrModelFile = this.getResourceStream(modelPath+File.separator+ FILENAME.IRREGULAR_MODEL);
InputStream observationFile = this.getResourceStream(modelPath+File.separator+ FILENAME.OBSERVATION);
InputStream transitionFile = this.getResourceStream(modelPath+File.separator+ FILENAME.TRANSITION);

this.resources.loadPosTable(posTableFile);
this.resources.loadIrregular(irrModelFile);
this.resources.loadObservation(observationFile);
Expand Down
13 changes: 2 additions & 11 deletions src/test/java/kr/co/shineware/nlp/komoran/core/KomoranTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*******************************************************************************/
package kr.co.shineware.nlp.komoran.core;

import kr.co.shineware.nlp.komoran.constant.DEFAULT_MODEL;
import kr.co.shineware.nlp.komoran.model.KomoranResult;
import kr.co.shineware.nlp.komoran.model.Token;
import kr.co.shineware.nlp.komoran.util.KomoranCallable;
Expand All @@ -38,8 +39,7 @@ public class KomoranTest {

@Before
public void init() throws Exception {
// this.komoran = new Komoran("models_full");
this.komoran = new Komoran();
this.komoran = new Komoran(DEFAULT_MODEL.LIGHT);
}

@Test
Expand Down Expand Up @@ -102,7 +102,6 @@ public void multiThreadSpeedTest() throws ExecutionException, InterruptedExcepti

List<Future<KomoranResult>> komoranList = new ArrayList<>();
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(2);
int count = 0;


for (String line : lines) {
Expand All @@ -124,19 +123,11 @@ public void multiThreadSpeedTest() throws ExecutionException, InterruptedExcepti
System.out.println("Elapsed time : "+(end-begin));
}

private void flush(List<Future<KomoranResult>> komoranList, String analyze) throws ExecutionException, InterruptedException {
for (Future<KomoranResult> komoranResultFuture : komoranList) {
KomoranResult komoranResult = komoranResultFuture.get();
}
}

@Test
public void threadSafeTest() throws ExecutionException, InterruptedException {
List<String> lines = FileUtil.load2List("in.txt");


List<CallableImpl> invokeTargetList = new ArrayList<>();
List<Future<String>> futureList = new ArrayList<>();
ExecutorService executorService = Executors.newFixedThreadPool(10);
for(int k=0;k<100000;k++) {
long b = System.currentTimeMillis();
Expand Down

0 comments on commit 906b2db

Please sign in to comment.