代码之家  ›  专栏  ›  技术社区  ›  The_Ghost

如何在rowlex中将数组属性为自定义类型

  •  0
  • The_Ghost  · 技术社区  · 16 年前

    我有一些自定义类型:

    [RdfSerializable]
    public class Item
    {
        [RdfProperty(true)]
        public string Name { get; set; }
    }
    

    以及其他具有项数组的类型:

    [RdfSerializable]
    public class Container
    {
          // ... some code
    
          // if this attribute is missing, then this property will not be exported as array
          [CardinalityRestriction(1, 100)]     
          [RdfProperty(false)]
          public Item[] MyArray { get { return mMyArray; } }
    }
    

    如果我从myarray中删除cardinalityrestriction属性,它将被owlgrinder.exe导出为单个项,而不是作为项的数组。

    是否有其他方法定义数组而不将其约束到某个元素范围?

    1 回复  |  直到 15 年前
        1
  •  1
  •   ROWLEX Admin    15 年前

    ROWLEX OntologyExtractor的行为正确(owlgrinder读取本体并生成程序集)。本体抽取器读取程序集并吐出本体)。根据 OWL specifications 如果没有与owl属性关联的基数限制,则假定其基数为“零或更多”。如果希望属性不是“数组属性”,则需要应用基数限制。它的简写是使owl属性 functional property ,其中基数为0或1。

    所以你需要做的就是去掉[cardinalityresection(1100)]的装饰,你就得到了你想要的。

    [编辑:回复评论] 我复制了您的案例,删除了基数限制,并且OntologyExtractor生成了以下本体:

    <?xml version="1.0"?>
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdfschema="http://www.w3.org/2000/01/rdf-schema#">
        <owl:Ontology rdf:about="http://www.test.com/MyOntology" />
        <owl:Class rdf:about="http://www.test.com/MyOntology#Item" />
        <owl:DatatypeProperty rdf:about="http://www.test.com/MyOntology#Name">
            <rdfschema:domain rdf:resource="http://www.test.com/MyOntology#Item" />
            <rdfschema:range rdf:resource="http://www.w3.org/2001/XMLSchema#string" />
            <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty" />
        </owl:DatatypeProperty>
        <owl:ObjectProperty rdf:about="http://www.test.com/MyOntology#MyArray">
            <rdfschema:domain>
                <owl:Class rdf:about="http://www.test.com/MyOntology#Container" />
            </rdfschema:domain>
            <rdfschema:range rdf:resource="http://www.test.com/MyOntology#Item" />
        </owl:ObjectProperty>
    </rdf:RDF>
    

    此本体允许您创建RDF文件,其中容器对象有零个或多个通过myarray owl属性链接的项。

    推荐文章