【问题标题】:Create Protege Readable Ontology from .NET从 .NET 创建 Protege 可读本体
【发布时间】:2015-09-24 19:28:26
【问题描述】:

我正在尝试从 .NET 创建一个 protégé 可读本体。

我从一个 4GB 的 .nt 文件开始,并解析出我希望使用的所需类和实例。这些都存储在内存中,因为我把它降低到不到 1 分钟,大约 1GB。它们现在的形式为Dictionary<String,HashSet<String>>。下一步是获取该数据并将其移动到 OWL 本体中。有什么地方可以开始手动循环并执行此操作吗?我所有的研究都指向我使用 Manchester OWL,但我能找到的所有东西都是用于不符合我需求的现有工具。我正在寻找可能使用 LINQ to XML 做一个简单的循环,我不确定如何格式化它或在哪里寻找如何执行此操作。

谢谢 吉米

【问题讨论】:

标签: c# linq-to-xml ontology


【解决方案1】:

你可以从这个开始

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string definition =
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<Ontology xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
                    " xsi:schemaLocation=\"http://www.w3.org/2002/07/owl# http://www.w3.org/2009/09/owl2-xml.xsd\"" +
                    " xmlns=\"http://www.w3.org/2002/07/owl#\"" +
                    " xml:base=\"http://example.com/myOntology\"" +
                    " ontologyIRI=\"http://example.com/myOntology\">" +
                "</Ontology>";

            XDocument doc = XDocument.Parse(definition);
            XElement ontology = (XElement)doc.FirstNode;
            XNamespace ns = ontology.Name.Namespace;

            ontology.Add(new XElement[] {
                new XElement(ns + "Prefix", new XAttribute[] {
                       new XAttribute("name", "myOnt"),
                       new XAttribute("IRI", "http://example.com/myOntology#")
                }),
                new XElement(ns + "Import", "http://example.com/someOtherOntology")
            });

        }
    }
}
​

【讨论】:

  • 这让我走上了正轨。事实证明它对于 protege 来说太大了,至少无法在 16 gig 机器上处理,所以我们以不同的方式解析它。感谢您的帮助。
  • @Jimmy 你是怎么解析的?
猜你喜欢
  • 1970-01-01
  • 2016-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多