OWLAPI在OWL中的类层次结构的节点数据格式

时间:2018-08-15 05:31:32

标签: java owl-api

我想提取OWL本体中的所有类节点,并且将类节点编写为以下格式:

[{
   name: node1
   children: [{
       name: node11
      },
      {name: node12,
       children: [{
              name:node121,
              name:node122
      }]
}]
}]

我使用printHierachy方法提取类层次结构,但是如何将其转换为以上格式?

1 个答案:

答案 0 :(得分:0)

您应该为override对象使用Node toString方法:

@Override
public String toString() {
    StringBuilder builder = new StringBuilder(  );

    builder.append( "{ name: "  );
    builder.append( this.name  );

    builder.append( ", children: [ " );
    if(this.children != null ) {
        for ( Node n : this.children ) {
            builder.append( n.toString() + ", " );
        }
    }
    builder.append( " ] }" );
    return builder.toString();

}