Module: Nlpir

Defined in:
lib/nlpir.rb,
lib/nlpir/version.rb

Constant Summary collapse

NLPIR_FALSE =
0
NLPIR_TRUE =
1
POS_MAP_NUMBER =
4
ICT_POS_MAP_FIRST =

计算所一级标注集

1
ICT_POS_MAP_SECOND =

计算所二级标注集

0
PKU_POS_MAP_SECOND =

北大二级标注集

2
PKU_POS_MAP_FIRST =

北大一级标注集

3
POS_SIZE =
40
Result_t =
struct ['int start','int length',"char  sPOS[#{POS_SIZE}]",'int iPOS',
'int word_ID','int word_type','double weight']
GBK_CODE =

默认支持GBK编码

0
UTF8_CODE =

UTF8编码

GBK_CODE + 1
BIG5_CODE =

BIG5编码

GBK_CODE + 2
GBK_FANTI_CODE =

GBK编码,里面包含繁体字

GBK_CODE + 3
NLPIR_Init_rb =
Fiddle::Function.new(
  libm['_Z10NLPIR_InitPKci'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_INT],
  Fiddle::TYPE_INT
)
NLPIR_Exit_rb =
Fiddle::Function.new(
  libm['_Z10NLPIR_Exitv'],
  [],
  Fiddle::TYPE_INT
)
NLPIR_ImportUserDict_rb =
Fiddle::Function.new(
  libm['_Z20NLPIR_ImportUserDictPKc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_INT
)
NLPIR_ParagraphProcess_rb =
Fiddle::Function.new(
  libm['_Z22NLPIR_ParagraphProcessPKci'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_INT],
  Fiddle::TYPE_VOIDP
)
NLPIR_ParagraphProcessA_rb =
Fiddle::Function.new(
  libm['_Z23NLPIR_ParagraphProcessAPKcPib'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_VOIDP
)
NLPIR_FileProcess_rb =
Fiddle::Function.new(
  libm['_Z17NLPIR_FileProcessPKcS0_i'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT],
  Fiddle::TYPE_DOUBLE
)
NLPIR_GetParagraphProcessAWordCount_rb =
Fiddle::Function.new(
  libm['_Z35NLPIR_GetParagraphProcessAWordCountPKc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_INT
)
NLPIR_ParagraphProcessAW_rb =
Fiddle::Function.new(
  libm['_Z24NLPIR_ParagraphProcessAWiP8result_t'],
  [Fiddle::TYPE_INT,Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_INT
)
NLPIR_AddUserWord_rb =
Fiddle::Function.new(
  libm['_Z17NLPIR_AddUserWordPKc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_INT
)
NLPIR_SaveTheUsrDic_rb =
Fiddle::Function.new(
  libm['_Z19NLPIR_SaveTheUsrDicv'],
  [],
  Fiddle::TYPE_INT
)
NLPIR_DelUsrWord_rb =
Fiddle::Function.new(
  libm['_Z16NLPIR_DelUsrWordPKc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_INT
)
NLPIR_GetKeyWords_rb =
Fiddle::Function.new(
  libm['_Z17NLPIR_GetKeyWordsPKcib'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_INT,Fiddle::TYPE_INT],
  Fiddle::TYPE_VOIDP
)
NLPIR_GetFileKeyWords_rb =
Fiddle::Function.new(
  libm['_Z21NLPIR_GetFileKeyWordsPKcib'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_INT,Fiddle::TYPE_INT],
  Fiddle::TYPE_VOIDP
)
NLPIR_GetNewWords_rb =
Fiddle::Function.new(
  libm['_Z17NLPIR_GetNewWordsPKcib'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_INT,Fiddle::TYPE_INT],
  Fiddle::TYPE_VOIDP
)
NLPIR_GetFileNewWords_rb =
Fiddle::Function.new(
  libm['_Z21NLPIR_GetFileNewWordsPKcib'],
  [Fiddle::TYPE_VOIDP,Fiddle::TYPE_INT,Fiddle::TYPE_INT],
  Fiddle::TYPE_VOIDP
)
NLPIR_FingerPrint_rb =
Fiddle::Function.new(
  libm['_Z17NLPIR_FingerPrintPKc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_LONG
)
NLPIR_SetPOSmap_rb =
Fiddle::Function.new(
  libm['_Z15NLPIR_SetPOSmapi'],
  [Fiddle::TYPE_INT],
  Fiddle::TYPE_INT
)
NLPIR_NWI_Start_rb =
Fiddle::Function.new(
  libm['_Z15NLPIR_NWI_Startv'],
  [],
  Fiddle::TYPE_INT
)
NLPIR_NWI_AddFile_rb =
Fiddle::Function.new(
  libm['_Z17NLPIR_NWI_AddFilePKc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_INT
)
NLPIR_NWI_AddMem_rb =
Fiddle::Function.new(
  libm['_Z16NLPIR_NWI_AddMemPKc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_INT
)
NLPIR_NWI_Complete_rb =
Fiddle::Function.new(
  libm['_Z18NLPIR_NWI_Completev'],
  [],
  Fiddle::TYPE_INT
)
NLPIR_NWI_GetResult_rb =
Fiddle::Function.new(
  libm['_Z19NLPIR_NWI_GetResultb'],
  [Fiddle::TYPE_INT],
  Fiddle::TYPE_VOIDP
)
NLPIR_NWI_Result2UserDict_rb =
Fiddle::Function.new(
  libm['_Z25NLPIR_NWI_Result2UserDictv'],
  [],
  Fiddle::TYPE_VOIDP
)
VERSION =
"0.0.3"

Instance Method Summary collapse

Instance Method Details

#NLPIR_AddUserWord(sWord) ⇒ Object



214
215
216
# File 'lib/nlpir.rb', line 214

def NLPIR_AddUserWord(sWord)
  NLPIR_AddUserWord_rb.call(sWord)
end

#NLPIR_DelUsrWord(sWord) ⇒ Object



222
223
224
# File 'lib/nlpir.rb', line 222

def NLPIR_DelUsrWord(sWord)
  NLPIR_DelUsrWord_rb.call(sWord)
end

#NLPIR_ExitObject



168
169
170
# File 'lib/nlpir.rb', line 168

def NLPIR_Exit()
  NLPIR_Exit_rb.call()
end

#NLPIR_FileProcess(sSourceFilename, sResultFilename, bPOStagged = NLPIR_TRUE) ⇒ Object



193
194
195
# File 'lib/nlpir.rb', line 193

def NLPIR_FileProcess(sSourceFilename, sResultFilename, bPOStagged=NLPIR_TRUE)
  NLPIR_FileProcess_rb.call(sSourceFilename, sResultFilename, bPOStagged)
end

#NLPIR_FingerPrint(sLine) ⇒ Object



242
243
244
# File 'lib/nlpir.rb', line 242

def NLPIR_FingerPrint(sLine)
  NLPIR_FingerPrint_rb.call(sLine)
end

#NLPIR_GetFileKeyWords(sTextFile, nMaxKeyLimit = 50, bWeightOut = NLPIR_FALSE) ⇒ Object



230
231
232
# File 'lib/nlpir.rb', line 230

def NLPIR_GetFileKeyWords(sTextFile, nMaxKeyLimit=50, bWeightOut=NLPIR_FALSE)
  NLPIR_GetFileKeyWords_rb.call(sTextFile, nMaxKeyLimit, bWeightOut).to_s
end

#NLPIR_GetFileNewWords(sTextFile, nMaxKeyLimit = 50, bWeightOut = NLPIR_FALSE) ⇒ Object



238
239
240
# File 'lib/nlpir.rb', line 238

def NLPIR_GetFileNewWords(sTextFile, nMaxKeyLimit=50, bWeightOut=NLPIR_FALSE)
  NLPIR_GetFileNewWords_rb.call(sTextFile, nMaxKeyLimit, bWeightOut).to_s
end

#NLPIR_GetKeyWords(sLine, nMaxKeyLimit = 50, bWeightOut = NLPIR_FALSE) ⇒ Object



226
227
228
# File 'lib/nlpir.rb', line 226

def NLPIR_GetKeyWords(sLine, nMaxKeyLimit=50, bWeightOut=NLPIR_FALSE)
  NLPIR_GetKeyWords_rb.call(sLine, nMaxKeyLimit, bWeightOut).to_s
end

#NLPIR_GetNewWords(sLine, nMaxKeyLimit = 50, bWeightOut = NLPIR_FALSE) ⇒ Object



234
235
236
# File 'lib/nlpir.rb', line 234

def NLPIR_GetNewWords(sLine, nMaxKeyLimit=50, bWeightOut=NLPIR_FALSE)
  NLPIR_GetNewWords_rb.call(sLine, nMaxKeyLimit, bWeightOut).to_s
end

#NLPIR_GetParagraphProcessAWordCount(sParagraph) ⇒ Object



197
198
199
# File 'lib/nlpir.rb', line 197

def NLPIR_GetParagraphProcessAWordCount(sParagraph)
  NLPIR_GetParagraphProcessAWordCount_rb.call(sParagraph)
end

#NLPIR_ImportUserDict(sFilename) ⇒ Object



172
173
174
# File 'lib/nlpir.rb', line 172

def NLPIR_ImportUserDict(sFilename)
  NLPIR_ImportUserDict_rb.call(sFilename)
end

#NLPIR_Init(sInitDirPath = nil, encoding = UTF8_CODE, filepath) ⇒ Object

–函数



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/nlpir.rb', line 151

def NLPIR_Init(sInitDirPath=nil , encoding=UTF8_CODE, filepath)
  filepath += "/Data/"
  if File.exist?(filepath)==false
    FileUtils.mkdir(filepath)
    filemother = File.expand_path("../Data/", __FILE__)
    list=Dir.entries(filemother)
    list.each_index do |x| 
      t = filemother+"/"+list[x]
      FileUtils.cp(t,filepath) if !File.directory?(t) 
    end
  end
  
  
  NLPIR_Init_rb.call(sInitDirPath,encoding)

end

#NLPIR_NWI_AddFile(sFilename) ⇒ Object



254
255
256
# File 'lib/nlpir.rb', line 254

def NLPIR_NWI_AddFile(sFilename)
  NLPIR_NWI_AddFile_rb.call(sFilename)
end

#NLPIR_NWI_AddMem(sFilename) ⇒ Object



258
259
260
# File 'lib/nlpir.rb', line 258

def NLPIR_NWI_AddMem(sFilename)
  NLPIR_NWI_AddMem_rb.call(sFilename)
end

#NLPIR_NWI_CompleteObject



262
263
264
# File 'lib/nlpir.rb', line 262

def NLPIR_NWI_Complete()
  NLPIR_NWI_Complete_rb.call()
end

#NLPIR_NWI_GetResult(bWeightOut = NLPIR_FALSE) ⇒ Object



266
267
268
# File 'lib/nlpir.rb', line 266

def NLPIR_NWI_GetResult( bWeightOut = NLPIR_FALSE)
  NLPIR_NWI_GetResult_rb.call(bWeightOut)
end

#NLPIR_NWI_Result2UserDictObject



270
271
272
# File 'lib/nlpir.rb', line 270

def NLPIR_NWI_Result2UserDict()
  NLPIR_NWI_Result2UserDict_rb.call()
end

#NLPIR_NWI_StartObject



250
251
252
# File 'lib/nlpir.rb', line 250

def NLPIR_NWI_Start()
  NLPIR_NWI_Start_rb.call()
end

#NLPIR_ParagraphProcess(sParagraph, bPOStagged = NLPIR_TRUE) ⇒ Object



176
177
178
# File 'lib/nlpir.rb', line 176

def NLPIR_ParagraphProcess(sParagraph, bPOStagged=NLPIR_TRUE)
  NLPIR_ParagraphProcess_rb.call(sParagraph, bPOStagged).to_s
end

#NLPIR_ParagraphProcessA(sParagraph) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/nlpir.rb', line 180

def NLPIR_ParagraphProcessA(sParagraph)
  resultCount = NLPIR_GetParagraphProcessAWordCount(sParagraph)
  pResultCount = Fiddle::Pointer.to_ptr(resultCount)
  p = NLPIR_ParagraphProcessA_rb.call(sParagraph, pResultCount.ref.to_i)
  pVecResult = Fiddle::Pointer.new(p.to_i)
  words_list = []
  words_list << Result_t.new(pVecResult)
  for i in 1...resultCount  do
      words_list << Result_t.new(pVecResult += Result_t.size)
  end
  return words_list
end

#NLPIR_ParagraphProcessAW(sParagraph) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/nlpir.rb', line 201

def NLPIR_ParagraphProcessAW(sParagraph)
  free = Fiddle::Function.new(Fiddle::RUBY_FREE, [TYPE_VOIDP], TYPE_VOID)
  resultCount = NLPIR_GetParagraphProcessAWordCount(sParagraph)
  pVecResult = Pointer.malloc(Result_t.size*resultCount,free)
  NLPIR_ParagraphProcessAW_rb.call(resultCount,pVecResult)
  words_list = []
  words_list << Result_t.new(pVecResult)
  for i in 1...resultCount do
      words_list << Result_t.new(pVecResult+=Result_t.size)
  end
  return words_list
end

#NLPIR_SaveTheUsrDicObject



218
219
220
# File 'lib/nlpir.rb', line 218

def NLPIR_SaveTheUsrDic()
  NLPIR_SaveTheUsrDic_rb.call()
end

#NLPIR_SetPOSmap(nPOSmap) ⇒ Object



246
247
248
# File 'lib/nlpir.rb', line 246

def NLPIR_SetPOSmap(nPOSmap)
  NLPIR_SetPOSmap_rb.call(nPOSmap)
end