前向后向规则 Xml DTD

发布于 2024-08-09 18:30:05 字数 412 浏览 1 评论 0 原文

我想使用 DTD 建模一个简单的 (IF then) 规则。这就是我想出的:

<!ELEMENT forward    ((rule | fact)*)> 

<!ELEMENT rule       (if, then)> 

<!ELEMENT fact       (#PCDATA)> 

<!ELEMENT if         (#PCDATA)> 

<!ELEMENT then       (#PCDATA)>

这是前向规则的 dtd (p => c)。我还想使用结论和前提元素而不是 if 和 then 来对后向规则( c <= p)进行建模。我是否只需要更改 if 和 then 为 cons 和 prem 还是我需要做其他事情?我很欣赏你的回复。

I want to model a simple (IF Then) rule using DTD. This is what I have come up with:

<!ELEMENT forward    ((rule | fact)*)> 

<!ELEMENT rule       (if, then)> 

<!ELEMENT fact       (#PCDATA)> 

<!ELEMENT if         (#PCDATA)> 

<!ELEMENT then       (#PCDATA)>

This is a dtd for a forward rule ( p => c). I want to model the backward rule as well ( c <= p) using conclusion and premise elements instead of if and then. Do I just need to change if and then to cons and prem or do I need to do something else. I appreciate your responses.

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

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

发布评论

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

评论(2

缱倦旧时光 2024-08-16 18:30:05

XML DTD 只是为您的模型提供语法。例如,您可以编写:

<rule>
  <if>is raining</if>  
  <then>pigs will fly</then>
</rule>

并且

<rule>
  <cons>pigs will fly</cons>  
  <prem>is raining</prem>
</rule>

但是您必须提供连接这两者的任何逻辑并自己编写。 XML 没有给您提供具体的帮助。

我建议你看看 Prolog 等语言。

XML DTDs simply give you a syntax for your model. You could, for example, write:

<rule>
  <if>is raining</if>  
  <then>pigs will fly</then>
</rule>

and

<rule>
  <cons>pigs will fly</cons>  
  <prem>is raining</prem>
</rule>

but you will have to provide any logic connecting these two and write it yourself. XML gives you no specific help.

I would suggest you look at languages such as Prolog.

爱*していゐ 2024-08-16 18:30:05

对于 XML 词汇表来说,可能比从 XSLT 中“借用”等效功能更糟糕(即使您不使用相同的名称)。

请参阅 http://www.w3.org/TR/ xslt#section-Conditional-Processing-with-xsl:if

其语法的一般形式是

<xsl:if test = boolean-expression>
  <!-- Content: template -->
</xsl:if>

Forforwarding 等,您的问题太笼统,无法给出精确的答案。如果你想链接测试,你可以给每个测试一个 id,然后有类似 的内容。引用下一个要应用的测试的 id 的元素。或者,您可以构建更复杂的条件处理词汇表,可能(再次)基于 XSLT 模型(请参阅 http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose)。

DTD 为您提供语法,但没有语义,因此您想要的 XML 的任何功能都必须在您的应用程序中开发。

For an XML vocabulary could do a lot worse than "borrow" the equivalent functionality from XSLT (even if you don't use the same names).

See http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:if

The general form of its syntax is

<xsl:if test = boolean-expression>
  <!-- Content: template -->
</xsl:if>

For forwarding and such-like, your problem is too general to give a precise answer. If you want to chain tests you might give each of your tests an id and then have something like a <forward to-test="some-id"/> element which references the id of the next test to be applied. Or you might build more complicated conditional processing vocabulary, maybe based (again) on XSLT's model (see http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose).

The DTD gives you syntax but no semantics, so any functionality you want around your XML will have to be developed in your application.

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