找回密码
 欢迎注册
搜索
热搜: 活动 交友 discuz
查看: 2824|回复: 0

C#处理 rdf 的例子, SemWeb的helloworld

[复制链接]
发表于 2007-5-12 15:33:49 | 显示全部楼层 |阅读模式
http://razor.occams.info/code/semweb/
以上的link有c#处理rdf的库,owl的处理的话,把owl当成rdf就可以了,虽然效率不是很好,终究还是可用的咚咚,不知道各位还知道有其他C#的Owl库没,请赐教。

我还用过其他一些 比如 drive rdf .net 和 EulerSharp 和Jena.net 不过觉得不太好用,用过这些的朋友们也请交换点意见如何?


  1. // This example creates a few RDF statements and adds
  2. // them to a MemoryStore.  Then it writes out the
  3. // statements in RDF/XML format to the console.  Note
  4. // that the implicit string-to-Entity and string-to-
  5. // Literal conversion operators are being used.

  6. using System;
  7. using SemWeb;

  8. public class Example {

  9.     const string RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";

  10.     public static void Main() {
  11.         //建立一个留内存处理区域
  12.         MemoryStore store = new MemoryStore();
  13.         
  14.         //这一点由于采用了RDF的概念,和OWL的jena编程有所不同,把所有的element and properity都声明为Entity
  15.         Entity computer = new Entity("http://example.org/computer");
  16.         Entity says = "http://example.org/says";
  17.         Entity wants = "http://example.org/wants";
  18.         Entity desire = new BNode();
  19.         Entity description = new Entity("http://example.org/description");
  20.         
  21.         //在刚才声明的store中按照RDF的三元方式添加Statement: the subject is the URL, computer
  22.         //the predicate is the word says the object is the phrase (Literal)"Hello world!"

  23.         store.Add(new Statement(computer, says, (Literal)"Hello world!"));
  24.         store.Add(new Statement(computer, wants, desire));
  25.         store.Add(new Statement(desire, description, (Literal)"to be human"));
  26.         store.Add(new Statement(desire, RDF+"type", (Entity)"http://example.org/Desire"));
  27.         
  28.         //输出结果
  29.         using (RdfWriter writer = new RdfXmlWriter(Console.Out)) {
  30.             writer.Namespaces.AddNamespace("http://example.org/", "ex");
  31.             writer.Write(store);
  32.         }
  33.     }
  34. }
复制代码

[ 本帖最后由 smallpotato 于 2007-5-12 15:45 编辑 ]
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

快速回复 返回顶部 返回列表