我正在尝试在Stanford.NLP.NET site处运行介绍性的F#示例。这是我的代码:
#I @"..\packages\Stanford.NLP.NER.3.7.0.1\lib"
#I @"..\packages\IKVM.8.1.5717.0\lib"
#r @"..\packages\IKVM.8.1.5717.0\lib\IKVM.OpenJDK.Core.dll"
#r @"..\packages\IKVM.8.1.5717.0\lib\IKVM.OpenJDK.Util.dll"
#r @"..\packages\Stanford.NLP.NER.3.7.0.1\lib\stanford-ner.dll"
open System
open System.IO
open edu.stanford.nlp.ie.crf
open System.Globalization
let classifiersDir =
[|__SOURCE_DIRECTORY__; ".."; "data"; "NLPClassifiers"; "stanford-ner-2016-10-31"; "classifiers"|]
let classifier =
CRFClassifier.getClassifierNoExceptions(
Array.concat [|classifiersDir; [|"english.all.3class.distsim.crf.ser.gz"|]|] |> Path.Combine
)
let str1 = "Good afternoon John Doe, how are you today?"
let str2 = "I go to Stanford University, which is in Caliornia."
printfn "%s" (classifier.classifyToString str1)
printfn "%s" (classifier.classifyToString str2)
当我尝试运行上面的代码时出现以下异常:
System.TypeInitializationException: The type initializer for 'edu.stanford.nlp.util.Timing' threw an exception. ---> System.TypeInitializationException: The type initializer for 'java.util.ResourceBundle' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
at IKVM.Internal.AssemblyClassLoader.<FindResources>d__0.MoveNext()
at IKVM.Internal.AssemblyClassLoader.<FindDelegateResources>d__e.MoveNext()
at IKVM.Internal.AssemblyClassLoader.<GetResources>d__14.MoveNext()
at ikvm.runtime.EnumerationWrapper..ctor(IEnumerable enumerable)
at IKVM.NativeCode.ikvm.runtime.AssemblyClassLoader.getResources(ClassLoader _this, String name)
at java.util.ServiceLoader.LazyIterator.hasNextService()
at java.util.ServiceLoader.LazyIterator.hasNext()
at java.util.ServiceLoader.1.hasNext()
at java.util.ResourceBundle..cctor()
--- End of inner exception stack trace ---
at java.util.ResourceBundle.getBundle(String baseName, Locale targetLocale, Control control, CallerID )
at sun.util.resources.LocaleData.1.run()
at sun.util.resources.LocaleData.1.run()
at java.security.AccessController.doPrivileged(Object , AccessControlContext , CallerID )
at java.security.AccessController.doPrivileged(PrivilegedAction action, CallerID )
at sun.util.resources.LocaleData.getBundle(String baseName, Locale locale)
at sun.util.resources.LocaleData.getNumberFormatData(Locale locale)
at sun.util.locale.provider.LocaleResources.getDecimalFormatSymbolsData()
at java.text.DecimalFormatSymbols.initialize(Locale )
at java.text.DecimalFormatSymbols..ctor(Locale locale)
at sun.util.locale.provider.DecimalFormatSymbolsProviderImpl.getInstance(Locale locale)
at java.text.DecimalFormatSymbols.getInstance(Locale locale)
at java.text.DecimalFormat..ctor(String pattern)
at edu.stanford.nlp.util.Timing..cctor()
--- End of inner exception stack trace ---
at edu.stanford.nlp.util.Timing..ctor()
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(String loadPath, Properties props)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifierNoExceptions(String loadPath, Properties props)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifierNoExceptions(String loadPath)
at edu.stanford.nlp.ie.crf.CRFClassifier.getClassifierNoExceptions(String loadPath)
at <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\Users\amit-\Downloads\Noodle\NLPTests\NLPTests\Tests.fsx:line 42
Stopped due to error
Stanford NLP library
似乎需要Visual Studio 15.0.0
。但我正在运行最新版本的Community Edition,即version 15.3.3
。我是否正确理解错误,或者是否存在异常的不同根本原因? (我甚至不确定我是否可以下载旧版本的Visual Studio Community Edition。)
提前感谢您的帮助。
修改
我做了一些研究,我能找到的唯一一个例外是the GitHub repository。我尝试了明确将CultureInfo
设置为en-US
的建议。但这还没有解决问题。