Skip to content

Commit

Permalink
initializenlp upon program starting since only English is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
xulihang committed Feb 19, 2021
1 parent d5299d9 commit b629901
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 109 deletions.
167 changes: 84 additions & 83 deletions BasicCAT/BasicCAT.b4j
Original file line number Diff line number Diff line change
Expand Up @@ -203,91 +203,91 @@ Library6=jxui
Library7=jsql
Library8=jrandomaccessfile
Library9=jb4xencryption
Module1=FileChooserUtils
Module10=RichTextArea
Module11=InputTextAreaBox
Module12=Theme
Module13=TM
Module14=FileUtils
Module15=xliffFilter
Module16=tikal
Module17=Utils
Module18=SearchAndReplaceRecorder
Module19=searchAndReplaceDialog
Module2=Project
Module20=PathSaver
Module21=MT
Module22=LangCodeSearchView
Module23=SearchView
Module24=LanguagePairSelector
Module25=TMManager
Module26=TermManager
Module27=TMDB
Module28=LanguageUtils
Module29=filterGenericUtils
Module3=segmentation
Module30=XMLUtils
Module31=idmlFilter
Module32=idmlUtils
Module33=TimestampCalculator
Module34=SimpleTag
Module35=editDistance
Module36=progressDialog
Module37=TextFlow
Module38=Previewer
Module39=opennlp
Module4=txtFilter
Module40=ITP
Module41=statistics
Module42=SegmentationRulesManager
Module43=SRX
Module44=MTCompare
Module45=dictWebView
Module46=EnumClass
Module47=jieba
Module48=XMLBuilder2
Module49=MTParamsFiller
Module5=Term
Module50=TMX
Module51=XmlNode
Module52=confirmReviewDialog
Module53=LanguageTool
Module54=XmlParser
Module55=Xml2Map
Module56=importDialog
Module57=pdfbox
Module58=SourceTextEditor
Module59=git
Module6=KeyValueStore
Module60=TagKind
Module61=PDF2TXT
Module62=TMEditor
Module63=HistoryViewer
Module64=serverLauncher
Module65=AutoSaver
Module66=ClientKVS
Module67=languageChooser
Module68=HistoryRecord
Module69=Map2Xml
Module7=ProjectSettings
Module70=ErrorReporter
Module71=OperationDialog
Module72=zip4j
Module73=icu4j
Module74=POIWord
Module75=FontPicker
Module76=TermEditor
Module77=InputBox
Module78=TBX
Module79=CallSubUtils
Module8=preTranslateDialog
Module80=viewSegment
Module81=coordinate
Module9=Preferences
Module1=AutoSaver
Module10=FileChooserUtils
Module11=FileUtils
Module12=filterGenericUtils
Module13=FontPicker
Module14=git
Module15=HistoryRecord
Module16=HistoryViewer
Module17=icu4j
Module18=idmlFilter
Module19=idmlUtils
Module2=CallSubUtils
Module20=importDialog
Module21=InputBox
Module22=InputTextAreaBox
Module23=ITP
Module24=jieba
Module25=KeyValueStore
Module26=LangCodeSearchView
Module27=languageChooser
Module28=LanguagePairSelector
Module29=LanguageTool
Module3=ClientKVS
Module30=LanguageUtils
Module31=Map2Xml
Module32=MT
Module33=MTCompare
Module34=MTParamsFiller
Module35=opennlp
Module36=OperationDialog
Module37=PathSaver
Module38=PDF2TXT
Module39=pdfbox
Module4=confirmReviewDialog
Module40=POIWord
Module41=Preferences
Module42=preTranslateDialog
Module43=Previewer
Module44=progressDialog
Module45=Project
Module46=ProjectSettings
Module47=RichTextArea
Module48=searchAndReplaceDialog
Module49=SearchAndReplaceRecorder
Module5=coordinate
Module50=SearchView
Module51=segmentation
Module52=SegmentationRulesManager
Module53=serverLauncher
Module54=SimpleTag
Module55=SourceTextEditor
Module56=SRX
Module57=statistics
Module58=TagKind
Module59=TBX
Module6=dictWebView
Module60=Term
Module61=TermEditor
Module62=TermManager
Module63=TextFlow
Module64=Theme
Module65=tikal
Module66=TimestampCalculator
Module67=TM
Module68=TMDB
Module69=TMEditor
Module7=editDistance
Module70=TMManager
Module71=TMX
Module72=txtFilter
Module73=Utils
Module74=viewSegment
Module75=xliffFilter
Module76=Xml2Map
Module77=XMLBuilder2
Module78=XmlNode
Module79=XmlParser
Module8=EnumClass
Module80=XMLUtils
Module81=zip4j
Module9=ErrorReporter
NumberOfFiles=88
NumberOfLibraries=26
NumberOfModules=81
Version=7.8
Version=8.9
@EndOfDesignText@
#Region Project Attributes
#MainFormWidth: 600
Expand Down Expand Up @@ -459,6 +459,7 @@ Sub init
Drag.Initialize(projectTreeTableView, "Drag")
loadPlugins
setupStyleSheets
initializeNLP("en")
'useMacMenuBar
'CSSUtils.SetStyleProperty(lowerRightSplitPane,"-fx-base","rgba(60, 63, 65, 255)")
End Sub
Expand Down Expand Up @@ -1668,7 +1669,7 @@ Sub checkVisibleRange
Dim currentVisibleRange As Range
currentVisibleRange=getVisibleRange(editorLV)
'If previousRange.lastIndex<>currentVisibleRange.lastIndex Or previousRange.firstIndex<>currentVisibleRange.firstIndex Then
Log("visible range changed")
' Log("visible range changed")
' previousRange=currentVisibleRange
currentProject.fillPane(currentVisibleRange.firstIndex,currentVisibleRange.lastIndex)
CallSubDelayed(Me,"ListViewParent_Resize")
Expand Down
4 changes: 2 additions & 2 deletions BasicCAT/BasicCAT.b4j.meta
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,6 @@ ModuleClosedNodes8=
ModuleClosedNodes80=
ModuleClosedNodes81=
ModuleClosedNodes9=
NavigationStack=Project,mi_Action,1470,0,Project,closeFile,270,0,Main,changeNeglectedStatus,944,0,searchAndReplaceDialog,resultListView_Action,551,0,FontPicker,Initialize,22,0,Project,changeSegment,1662,0,Main,searchTableView_Action,1553,0,Main,MenuBar1_Action,344,0,Main,ScrollTo,469,6,Project,openFile,263,5
NavigationStack=Main,init,170,3,Main,initializeNLP,201,0,Project,newProjectSetting,111,0,Project,open,97,5,Term,termsInASentence,274,0,ITP,getChunks,70,0,opennlp,Class_Globals,6,0,opennlp,Initialize,36,6,Term,termsInASentenceUsingIteration,323,0,Term,termsInASentenceUsingHashMap,287,4
SelectedBuild=0
VisibleModules=1,2,3,4,5,6,7,8,9,10,23,36,19,75
VisibleModules=10,45,51,72,60,25,46,42,41,47,35,23
13 changes: 10 additions & 3 deletions BasicCAT/Project.bas
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ Public Sub open(jsonPath As String)
initializeTM(path,True)
initializeTerm(path)
initializeHistory(path)
Main.initializeNLP(projectFile.Get("source"))
'If Main.nlp.currentLang<>projectFile.Get("source") Then
' Main.initializeNLP(projectFile.Get("source"))
'End If

If Main.preferencesMap.GetDefault("vcsEnabled",False)=True Then
If settings.GetDefault("git_enabled",False) Then
Expand All @@ -111,7 +113,9 @@ End Sub
Public Sub newProjectSetting(source As String,target As String)
projectFile.Put("source",source)
projectFile.Put("target",target)
Main.initializeNLP(source)
'If Main.nlp.currentLang<>projectFile.Get("source") Then
' Main.initializeNLP(projectFile.Get("source"))
'End If
Dim tmList As List
tmList.Initialize
Dim termList As List
Expand Down Expand Up @@ -1707,6 +1711,9 @@ Sub sourceTextArea_FocusChanged (HasFocus As Boolean)
End Sub

Sub targetTextArea_FocusChanged (HasFocus As Boolean)
If Main.editorLV.Items.Size=0 Then
Return
End If
Dim TextArea1 As RichTextArea
TextArea1=Sender
'Sleep(0)
Expand Down Expand Up @@ -2140,7 +2147,7 @@ Sub refillVisiblePane
End Sub

Public Sub fillPane(FirstIndex As Int, LastIndex As Int)
Log("fillPane")
'Log("fillPane")
If segments.Size=0 Then
Return
End If
Expand Down
51 changes: 30 additions & 21 deletions BasicCAT/opennlp.bas
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,40 @@ Sub Class_Globals
Private tokenizer As JavaObject
Private POSTagger As JavaObject
Private chunkerME As JavaObject
Public Initialized As Boolean
Public currentLang As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(lang As String)
Dim tokenizerIS As InputStream
tokenizerIS=File.OpenInput(File.Combine(File.DirApp,"model"),"en-token.bin")
Dim tokenizerModel As JavaObject
tokenizerModel.InitializeNewInstance("opennlp.tools.tokenize.TokenizerModel",Array(tokenizerIS))
tokenizer.InitializeNewInstance("opennlp.tools.tokenize.TokenizerME",Array(tokenizerModel))

Dim postaggerIS As InputStream
postaggerIS=File.OpenInput(File.Combine(File.DirApp,"model"),"en-pos-maxent.bin")
Dim posmodel As JavaObject
posmodel.InitializeNewInstance("opennlp.tools.postag.POSModel",Array(postaggerIS))
POSTagger.InitializeNewInstance("opennlp.tools.postag.POSTaggerME",Array(posmodel))

Dim chunkerIS As InputStream
chunkerIS=File.OpenInput(File.Combine(File.DirApp,"model"),"en-chunker.bin")
Dim chunkerModel As JavaObject
chunkerModel.InitializeNewInstance("opennlp.tools.chunker.ChunkerModel",Array(chunkerIS))
chunkerME.InitializeNewInstance("opennlp.tools.chunker.ChunkerME",Array(chunkerModel))

Dim dictIS As InputStream
dictIS=File.OpenInput(File.Combine(File.DirApp,"model"),"en-lemmatizer.dict")
lemmatizer.InitializeNewInstance("opennlp.tools.lemmatizer.DictionaryLemmatizer",Array(dictIS))
currentLang=lang
Dim tokenModelPath As String=File.Combine(File.Combine(File.DirApp,"model"),lang&"-token.bin")
Dim posModelPath As String=File.Combine(File.Combine(File.DirApp,"model"),lang&"-pos-maxent.bin")
Dim chunkerModelPath As String=File.Combine(File.Combine(File.DirApp,"model"),lang&"-chunker.bin")
Dim dictPath As String=File.Combine(File.Combine(File.DirApp,"model"),lang&"-lemmatizer.dict")
If File.Exists(tokenModelPath,"") And File.Exists(posModelPath,"") And File.Exists(chunkerModelPath,"") And File.Exists(dictPath,"") Then
Dim tokenizerIS As InputStream
tokenizerIS=File.OpenInput(tokenModelPath,"")
Dim tokenizerModel As JavaObject
tokenizerModel.InitializeNewInstance("opennlp.tools.tokenize.TokenizerModel",Array(tokenizerIS))
tokenizer.InitializeNewInstance("opennlp.tools.tokenize.TokenizerME",Array(tokenizerModel))
Dim postaggerIS As InputStream
postaggerIS=File.OpenInput(posModelPath,"")
Dim posModel As JavaObject
posModel.InitializeNewInstance("opennlp.tools.postag.POSModel",Array(postaggerIS))
POSTagger.InitializeNewInstance("opennlp.tools.postag.POSTaggerME",Array(posModel))
Dim chunkerIS As InputStream
chunkerIS=File.OpenInput(chunkerModelPath,"")
Dim chunkerModel As JavaObject
chunkerModel.InitializeNewInstance("opennlp.tools.chunker.ChunkerModel",Array(chunkerIS))
chunkerME.InitializeNewInstance("opennlp.tools.chunker.ChunkerME",Array(chunkerModel))
Dim dictIS As InputStream
dictIS=File.OpenInput(dictPath,"")
lemmatizer.InitializeNewInstance("opennlp.tools.lemmatizer.DictionaryLemmatizer",Array(dictIS))
Initialized=True
Else
Initialized=False
End If
End Sub

Public Sub tokenize(sentence As String) As String()
Expand Down

0 comments on commit b629901

Please sign in to comment.