我想提取OWL本体中的所有类节点,并且将类节点编写为以下格式:
[{
name: node1
children: [{
name: node11
},
{name: node12,
children: [{
name:node121,
name:node122
}]
}]
}]
我使用printHierachy方法提取类层次结构,但是如何将其转换为以上格式?
答案 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();
}