import clr
clr.AddReferenceToFileAndPath(r"D:/Work/NMecab/bin/LibNMeCab.dll")
import System
from System import *
import NMeCab
from NMeCab import *
import Spotfire.Dxp.Application
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Visuals import VisualContent
from System.Collections.Generic import HashSet
from System.IO import FileStream, FileMode, File, MemoryStream, SeekOrigin, StreamWriter
import System.String
from Spotfire.Dxp.Data.Import import TextDataReaderSettings
from Spotfire.Dxp.Data.Import import TextFileDataSource
def LoadCSV(dataTableName, stream):
settings = TextDataReaderSettings()
settings.Separator = ","
settings.AddColumnNameRow(0)
settings.ClearDataTypes(True)
settings.SetDataType(0, DataType.String)
settings.SetDataType(1, DataType.String)
settings.SetDataType(2, DataType.Real)
settings.SetDataType(3, DataType.Real)
stream.Seek(0, SeekOrigin.Begin)
fs = TextFileDataSource(stream, settings)
if Document.Data.Tables.Contains(dataTableName):
Document.Data.Tables[dataTableName].ReplaceData(fs)
else:
Document.Data.Tables.Add(dataTableName, fs)
stream = MemoryStream()
DicDir = r"D:\Work\NMecab\dic\ipadic"
t=MeCabTagger.Create(DicDir)
nodes = t.Parse( sentence )
result = ""
csvWriter = StreamWriter(stream) #, Encoding.UTF8)
csvWriter.WriteLine("COL01,COL02,COL03,COL04,COL05,COL06,COL07,COL08,COL09,COL10\r\n")
for node in nodes :
print node.Surface + "\t" + node.Feature
result = result + node.Surface + "\t" + node.Feature + "\n"
csvWriter.WriteLine(node.Surface + "," + node.Feature + "\n")
Document.Properties['NMeCabPaserResult'] = result
csvWriter.Flush()
LoadCSV("test", stream)
exit
コメント
コメントを投稿