从 RDF 文件生成 .DOT 文件

发布于 2024-11-28 22:33:52 字数 790 浏览 1 评论 0 原文

我有一个 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 文件?

I have an RDF file, from which I would like to generate a .dot file. I'd like to create a number of rules to style the nodes and the links between these nodes (such as a specific kind of arrow to represent a marriage relationship).

Here is an example of such a conversion "rule":

 <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>

I want to convert these lines to this result:

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

Then, to represent the marriage between two instances of the class person, the type of arrow will be "odot" and color "goldenrod":

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

How can I automatically generate the .dot file from RDF file, following rules like the one above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回忆追雨的时光 2024-12-05 22:33:52

这看起来对你有用: RDF-到点

This looks like it could work for you: RDF-to-Dot.

蓝戈者 2024-12-05 22:33:52

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>

xslt is my preferred way to create graphviz files from xml.

For you, the key part might look like this...

<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>
雨后彩虹 2024-12-05 22:33:52

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

This seems to be plenty up for the task: https://metacpan.org/pod/rdfdot

尛丟丟 2024-12-05 22:33:52

这个问题很老了(当时人们习惯把粉红色与女性联系起来:)但让我通过推广我的宠物来回答项目,因为它完全提供了所请求的定制类型。

以下规则(另存为 .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 数据(用海龟表示,因为现在 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 .

生成请求的图表:

ann 和 bob

the question is old (these were the days when people used to associate the color pink with the female gender :) but let me answer by promoting my pet project because it provides exactly the kind of customization requested.

The following rules (save as .n3 and use as custom rules in the playground) cover the example:

@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" 
    ] 
} 
.

Applied to the RDF data (expressed in turtle because XML is less used these days):

@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 .

produce the requested diagram:

ann and bob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文