小编acc*_*and的帖子

按名称选择子节点的子集

鉴于此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)

c# xml child-nodes

14
推荐指数
2
解决办法
4万
查看次数

检查字符串是否包含子字符串列表并保存匹配的字符串

这是我的情况:我有一个表示文本的字符串

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)

c# string contains

10
推荐指数
2
解决办法
4869
查看次数

使用LibSVM在Java代码中出现Weka错误"无法处理数字类"

我正在尝试使用基于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 任何人都可以解释我的错误在哪里?提前致谢

java classification weka libsvm

6
推荐指数
1
解决办法
9013
查看次数

标签 统计

c# ×2

child-nodes ×1

classification ×1

contains ×1

java ×1

libsvm ×1

string ×1

weka ×1

xml ×1