0
我的存储对象从我的本体保存到List中有问题。我在easy xml(非owl文件)上做了简单的例子,但现在我不知道如何才能为单身学生获取这些值。解析OWL文件并将其保存到列表
本体片段:
<Ontology />
.
. //here are 250 lines of declarations etc
.
<ClassAssertion>
<Class IRI="#Stacjonarny" />
<NamedIndividual IRI="#Student_3" />
</ClassAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#student_id" />
<NamedIndividual IRI="#Student_3" />
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#integer">3</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#imie" />
<NamedIndividual IRI="#Student_3" />
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">Grzegorz</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#nazwisko" />
<NamedIndividual IRI="#Student_3" />
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">Brzęczyszczykiewicz</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#wydział" />
<NamedIndividual IRI="#Student_3" />
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">Matematyczno-przyrodniczy</Literal>
</DataPropertyAssertion>
</Ontology>
我想取值形成“文字”标记,并把它们保存到列表student_3,4,5等为学生。
学生:
class Student
{
public int student_id { get; set; }
public string imie { get; set; }
public string nazwisko { get; set; }
public string wydzial { get; set; }
public Student(string imie, string nazwisko, string wydzial, int student_id)
{
this.student_id = student_id;
this.imie = imie;
this.nazwisko = nazwisko;
this.wydzial = wydzial;
}
}
昨天我花了差不多半天排练,现在我有这样的事情:
class Pobierz
{
List<classes.Student> studenci = new List<classes.Student>();
public void studentow()
{
XDocument xml = XDocument.Load("moja_ontologia.owl");
studenci = from student in xml.Root.Descendants("DataPropertyAssertion")
where student.Attribute("NamedIndividual").Value.Equals("Student")
select new classes.Student
{
imie = student.Element("")
}
}
}
在一个sentention:我怎样才能从“文字”标记中获取这些值?
此代码不会编译。没有空的构造函数为学生类,你不能分配一个LINQ查询声明为列表变量 –
你有看看https://github.com/bpellens/owldotnetapi –
@Sir Rufo 是的,我做了,但我需要做我自己的解析器,它是大学的小型项目。好吧,现在,当我有空的构造函数,并且我不会将查询分配给声明为List的变量(只是var studenci),那么结果是什么? – Kliwer