从 RDF 文件生成 .DOT 文件

问题描述 投票:0回答:4

我有一个 RDF 文件,我想从中生成一个 .dot 文件。我想创建一些规则来设计节点以及这些节点之间的链接的样式(例如表示婚姻关系的特定类型的箭头)。

以下是此类转换“规则”的示例:

 <person rdf:about="http://www.something.com/EGAnne"
   <j: DateBirth>1981</j: DateBirth>
   <j:Profession>Comptable</j:Profession>
   <j:Gender>Female</j:Gender>
 </j:person>

我想将这些行转换为这个结果:

a [label = "Anne \ n \ nD.Birth: 1981 \ nProfession: Accounting \ n", shape = circle, fillcolor = "pink" style = "filled", fontsize = "9", fontname = " Arial, bold "];

然后,为了表示类 person 的两个实例之间的婚姻,箭头的类型将为“odot”,颜色为“goldenrod”:

a -> j [arrowhead = "odot" arrowtail = "odot", dir = both, color = "goldenrod"]

如何按照上述规则自动从 RDF 文件生成 .dot 文件?

java rdf graphviz dot jena
4个回答
3
投票

这看起来对你有用:RDF-to-Dot


3
投票

xslt 是我从 xml 创建 graphviz 文件的首选方法。

对于你来说,关键部分可能是这样的......

<xsl:for-each select="whateverThePathIs/person">
<xsl:if test="(./j:Gender &eq; 'Female')">
# Output a node for a Female
</xsl:if>
<xsl:if test="(./j:Gender &eq; 'Male')">
# Output a node for a Male
</xsl:if>
</xsl:for-each>

1
投票

这似乎足以完成任务:https://metacpan.org/pod/rdfdot


0
投票

这个问题已经很老了(当时人们习惯将粉红色与女性联系起来:)但是让我通过推广我的宠物项目来回答,因为它提供了所要求的那种定制。

以下规则(另存为 .n3 并在 playground 中用作自定义规则)涵盖了示例:

@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix string: <http://www.w3.org/2000/10/swap/string#> .
@prefix : <http://www.something.com/> .
@prefix attr: <http://view/dot/attribute/> .
@prefix v: <http://view/> .

{ 
    ?p a :Person ;
        log:localName ?name ;
        :DateBirth ?date ;
        :Profession ?profession .
    (?name '\n D.Birth: ' ?date '\n Profession: ' ?profession) string:concatenation ?label .
}
=>
{
    v:digraph v:hasNode ?p .
    ?p attr:label ?label ;
        attr:shape "circle" ;
        attr:style "filled" ;
        attr:fontsize "9" ;
        attr:fontname "Arial, bold" ;
} .

{ ?p :Gender "Female"} => { ?p attr:fillcolor "pink" } .
{ ?p :Gender "Male"} => { ?p attr:fillcolor "lightblue" } .


{  
    ?p1 :marriedTo ?p2 
} 
=> 
{ 
    v:digraph v:hasEdge [ 
        v:source ?p1 ; 
        v:target ?p2 ; 
        attr:arrowhead "odot" ; 
        attr:arrowtail "odot" ; 
        attr:dir "both" ; 
        attr:color "goldenrod" 
    ] 
} 
.

应用于RDF数据(用turtle表示,因为现在XML使用较少):

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://www.something.com/> .

:Ann a :Person ;
   :DateBirth 1981 ;
   :Profession "Comptable" ;
   :Gender "Female" .

:Bob a :Person ;
   :DateBirth 1981 ;
   :Profession "Comptable" ;
   :Gender "Male" .

:Ann :marriedTo :Bob .

制作所要求的图表:

© www.soinside.com 2019 - 2024. All rights reserved.