鉴于此xml doc
<listOfItem>
<Item id="1">
<attribute1 type="foo"/>
<attribute2 type="bar"/>
<property type="x"/>
<property type="y"/>
<attribute3 type="z"/>
</Item>
<Item>
//... same child nodes
</Item>
//.... other Items
</listOfItems>
Run Code Online (Sandbox Code Playgroud)
给定这个xml文档,我想为每个"Item"节点选择"property"子节点.我怎么能直接在c#中做到这一点?使用"直接",我的意思是不选择Item的所有子节点,然后逐个检查.至今:
XmlNodeList nodes = xmldoc.GetElementsByTagName("Item");
foreach(XmlNode node in nodes)
{
doSomething()
foreach(XmlNode child in node.ChildNodes)
{
if(child.Name == "property")
{
doSomethingElse()
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的情况:我有一个表示文本的字符串
string myText = "Text to analyze for words, bar, foo";
Run Code Online (Sandbox Code Playgroud)
以及要在其中搜索的单词列表
List<string> words = new List<string> {"foo", "bar", "xyz"};
Run Code Online (Sandbox Code Playgroud)
我想知道最有效的方法,如果存在,获取文本中包含的单词列表,类似于:
List<string> matches = myText.findWords(words)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用基于LibSVM的分类器使用Weka,但是我遇到了这个错误:
Exception in thread "main" weka.core.UnsupportedAttributeTypeException:weka.classifiers.functions.LibSVM: Cannot handle numeric class!
at weka.core.Capabilities.test(Unknown Source)
at weka.core.Capabilities.test(Unknown Source)
at weka.core.Capabilities.test(Unknown Source)
at weka.core.Capabilities.testWithFail(Unknown Source)
at weka.classifiers.functions.LibSVM.buildClassifier(Unknown Source)
at imgclassifier.ImgClassifier.main(ImgClassifier.java:45)
Java Result: 1
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
try {
File f = new File("australian.txt");
LibSVMLoader loader = new LibSVMLoader();
loader.setSource(f);
Instances i = loader.getDataSet();
LibSVM svm = new LibSVM();
svm.buildClassifier(i);
}catch (IIOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
australian.txt就是一个例子:LibSVM DataSet 任何人都可以解释我的错误在哪里?提前致谢