请注意,我在F#和R(更多)方面是初学者,因此可能需要指向RTFM或其他资料;-)
我已经开始使用R和tm包进行一些文本数据挖掘。
我在R中有以下脚本,顺便说一下,它们非常像Ovid分析的示例(将“lgtext”替换为“txt”以获取真实示例,并将language =“no”替换为language =“lat”以在Ovid示例中运行它):
作为起步,我选择使用F#、R、Deedle和RProvider进行翻译。至于Deedle,我还没有使用过,可以忽略这部分内容...
然后,我尝试编写以下F#代码:
“扩展” R 脚本的原因是为了让我理解并使其正常工作。 经过一些来回,上述内容将运行,并显然与 R 中的 REPL 报告相同,唯一的例外是最后一行:
我已经开始使用R和tm包进行一些文本数据挖掘。
我在R中有以下脚本,顺便说一下,它们非常像Ovid分析的示例(将“lgtext”替换为“txt”以获取真实示例,并将language =“no”替换为language =“lat”以在Ovid示例中运行它):
library(tm)
library(SnowballC)
txt <- system.file("texts", "lgtextfull", package = "tm")
(lgorg <- VCorpus(DirSource(txt, encoding = "UTF-8"),
readerControl = list(language = "no")))
lg <- tm_map(lgorg , stripWhitespace)
作为起步,我选择使用F#、R、Deedle和RProvider进行翻译。至于Deedle,我还没有使用过,可以忽略这部分内容...
然后,我尝试编写以下F#代码:
#I "../packages/RProvider.1.0.17/"
#load "RProvider.fsx"
open RProvider
open RDotNet
open RProvider.``base``
open RProvider.tm
open RProvider.openNLP
open RProvider.SnowballC
let txt = R.system_file("texts", "lgtextfull", package = "tm", lib_loc = null, mustWork=true )
let lang = dict [("language", "no":>obj)]
let readerControl = R.list(lang)
let dirsource = R.DirSource(txt, encoding = "UTF-8")
let lgorg = R.VCorpus(dirsource, readerControl)
let lg = R.tm__map(lgorg, R.stripWhitespace)
“扩展” R 脚本的原因是为了让我理解并使其正常工作。 经过一些来回,上述内容将运行,并显然与 R 中的 REPL 报告相同,唯一的例外是最后一行:
let lg = R.tm__map(lgorg, R.stripWhitespace)
这会给出一个错误,例如:
System.Exception: No converter registered for type FSI_0006+lg@81 or any of its base types
at RProvider.RInteropInternal.convertToR@164.Invoke(String message) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 164
at Microsoft.FSharp.Core.PrintfImpl.go@523-3[b,c,d](String fmt, Int32 len, FSharpFunc`2 outputChar, FSharpFunc`2 outa, b os, FSharpFunc`2 finalize, FSharpList`1 args, Int32 i)
at Microsoft.FSharp.Core.PrintfImpl.run@521[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args)
at Microsoft.FSharp.Core.PrintfImpl.capture@540[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args, Type ty, Int32 i)
at <StartupCode$FSharp-Core>.$Reflect.Invoke@720-4.Invoke(T1 inp)
at RProvider.RInteropInternal.REngine.SetValue(REngine this, Object value, FSharpOption`1 symbolName) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 274
at RProvider.RInteropInternal.toR(Object value) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 287
at RProvider.RInterop.passArg@431(List`1 tempSymbols, Object arg) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 445
at RProvider.RInterop.argList@452-1.GenerateNext(IEnumerable`1& next) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 453
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable`1 argsByName, Object[] varArgs) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 450
at RProvider.RInterop.call(String packageName, String funcName, String serializedRVal, Object[] namedArgs, Object[] varArgs) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 494
at <StartupCode$FSI_0006>.$FSI_0006.main@() in C:\Users\helgeu\Documents\Visual Studio 2012\Projects\DisqusAnalyzer\DisqusAnalyzer.Lib\InteractiveSession.fsx:line 81
Stopped due to error
我必须承认,我对此一无所知,甚至谷歌也帮不了我;-)
有人能帮忙吗?有什么提示吗?这个应该工作吗?我做错了什么吗?