跳转到内容

实化:修订间差异

维基百科,自由的百科全书
删除的内容 添加的内容
InternetArchiveBot留言 | 贡献
补救2个来源,并将0个来源标记为失效。 #IABot (v1.5.2)
 
(未显示6个用户的17个中间版本)
第1行: 第1行:
{{NoteTA
'''实化'''({{lang-en|reification}})在[[计算机科学]]中把抽象的想法({{lang|en|idea}})转化为明确的[[数据模型]]或[[程序设计语言]]创建的其他对象的过程。通过实化,以前是隐式的、未表示的、可能是不可表示的被显式形成可概念(逻辑或计算)操作的。非正式地,实化也常被称作在特定系统范围内把某些东西变为“[[头等公民]]”。 实化是[[概念分析]]与[[知识表示]]中最常用的技术。
|G1 = IT
}}
在[[计算机科学]]中,'''实化'''({{lang-en|reification}})是把抽象的想法({{lang|en|idea}})转化为明确的[[数据模型]]或[[程序设计语言]]创建的其他对象的过程。通过实化,以前是隐式的、未表示的、可能是不可表示的被显式形成可概念(逻辑或计算)操作的。非正式地,实化也常被称作在特定系统范围内把某些东西变为“[[头等公民]]”即'''物件化'''。 实化是[[概念分析]]与[[知识表示]]中最常用的技术。


== 在程序设计语言中的实化与反射 ==
== 在程序设计语言中的实化与反射 ==
在程序设计语言中,把用户程序或者程序设计语言某一部分本来在[[编译期]]与[[运行期]]是隐式的,表示为语言自身,这一过程称为实化。这使得其对程序可当作普通数据来利用。在具有[[反射 (计算机科学)|反射]]的程序设计语言中,实化的数据表示了相关的被实化的领域。实化的数据常被称作[[头等对象]]。
在程序设计语言中,把用户程序或者程序设计语言某一部分本来在[[编译期]]与[[运行期]]是隐式的,表示为语言自身,这一过程称为实化。这使得其对程序可当作普通数据来利用。在具有[[反射式编程|反射]]的程序设计语言中,实化的数据表示了相关的被实化的领域。实化的数据常被称作[[头等对象]]。


*[[C语言]]中,把内存地址的底层细节实化为指针。例如:<code>char* buffer = (char*) 0xB800000;</code>
*[[C语言]]中,把内存地址的底层细节实化为指针。例如:<code>char* buffer = (char*) 0xB800000;</code>
* 基于[[λ演算]]的[[函数式程序设计语言]],把过程抽象(procedure abstraction)与过程应用(procedure application)的概念实化为λ表达式。
* 基于[[λ演算]]的[[函数式程序设计语言]],把过程抽象(procedure abstraction)与过程应用(procedure application)的概念实化为λ表达式。
* [[Scheme]]语言实化了[[]] (粗略说近似于运行期上下文环境)。
* [[Scheme]]语言实化了[[续]] (粗略说近似于运行期上下文环境)。
* [[C#]]实化了[[参数多态]]为多态,成为语言的头等特征。
* [[C♯|C#]]实化了[[参数多态]]为多态,成为语言的头等特征。
* [[Java]]中存在“可实化的类型”(reifiable types),其编译期信息在运行期保留并可完全利用。<ref>[http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.7 The Java Language Specification, section 4.7], Java SE 7 Edition</ref>
* [[Java]]中存在“可实化的类型”(reifiable types),其编译期信息在运行期保留并可完全利用。<ref>[http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.7 The Java Language Specification, section 4.7] {{Wayback|url=http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.7 |date=20120609071157 }}, Java SE 7 Edition</ref>
* [[REBOL]]实化了代码与数据的相互转换。
* [[REBOL]]实化了代码与数据的相互转换。
* 许多语言,如[[Curl (编程语言)|Curl]], [[JavaScript]], 与[[LISP|Lisp]]等提供了<code>eval</code>或<code>evaluate</code>过程使其有[[解释器]]的功能。
* 许多语言,如[[LISP|Lisp]][[JavaScript]][[Curl (编程语言)|Curl]]等提供了<code>eval</code>或<code>evaluate</code>过程使其有[[解释器]]的功能。
* [[Prolog]]语言的{{tsl|en|Logtalk}}框架提供了[[逻辑程序设计]]上下文的实化。
* [[Prolog]]语言的{{tsl|en|Logtalk}}框架提供了[[逻辑程序设计]]上下文的实化。
* [[Smalltalk]]与[[参与者]]的语言实化了块(block)与[[消息传递 (软件)|messages]]。<ref>{{cite web|url=http://c2.com/cgi/wiki?SmalltalkBlocksAndClosures |title=Smalltalk Blocks And Closures |publisher=C2.com |date=2009-10-15 |accessdate=2010-10-09}}</ref>
* [[Smalltalk]]与[[演员]]的语言实化了块(block)与[[消息传递|消息]]。<ref>{{cite web |url=http://c2.com/cgi/wiki?SmalltalkBlocksAndClosures |title=Smalltalk Blocks And Closures |publisher=C2.com |date=2009-10-15 |accessdate=2010-10-09 |archive-date=2010-02-06 |archive-url=https://web.archive.org/web/20100206073548/http://c2.com/cgi/wiki?SmalltalkBlocksAndClosures |dead-url=no }}</ref>
* [[Smalltalk]]-80把源代码编译为字节码,这是首例。<ref>J. Malenfant, M. Jacques and F.-N. Demers, [http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html A Tutorial on Behavioral Reflection and its Implementation] {{webarchive|url=https://web.archive.org/web/20100528214857/http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html |date=2010-05-28 }}</ref>
* [[Smalltalk]]-80把源代码编译为字节码,这是首例。<ref>J. Malenfant, M. Jacques and F.-N. Demers, [http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html A Tutorial on Behavioral Reflection and its Implementation] {{Wayback|url=http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html |date=20100528214857 }}</ref>

== 数据实化 ==
== 数据实化 ==
数据实化涉及在{{tsl|en|formal specification|形式规范}}中找到[[抽象数据类型]]的更为具体的表示。 <ref>[https://www.cs.tcd.ie/FME/original/FAQ/vdm/part13.html Formal Methods Europe, Frequently Asked Questions, part 13] {{webarchive|url=https://web.archive.org/web/20050312031255/http://www.cs.tcd.ie/FME/original/FAQ/vdm/part13.html |date=2005-03-12 }}.</ref> 例如,抽象数据类型集合(set)可以用map或者array来实化。
数据实化涉及在{{tsl|en|formal specification|形式规范}}中找到[[抽象数据类型]]的更为具体的表示。 <ref>[https://www.cs.tcd.ie/FME/original/FAQ/vdm/part13.html Formal Methods Europe, Frequently Asked Questions, part 13] {{Wayback|url=https://www.cs.tcd.ie/FME/original/FAQ/vdm/part13.html |date=20050312031255 }}.</ref> 例如,抽象数据类型集合(set)可以用map或者array来实化。


== 概念建模中的实化 ==
== 概念建模中的实化 ==
{{tsl|en|Conceptual model (computer science)|概念建模}}中广泛使用了实化。<ref>Antoni Olivé, Conceptual Modeling of Information Systems, Springer Verlag, 2007.</ref>实化一个关系(relationship)意味着把它视作一个实体。实化一个关系的目的是令其显式,必要时可以增加额外的信息。例如,关系''<code>IsMemberOf(member:Person, Committee)</code>''表示某人是某委员会的成员。下图左侧用表的形式列出了人''P1''是委员会''C1''与''C2''的成员;人''P2''是委员会''C1''成员。[[File:reification example1.png|500px|left|thumb|Example population of <code>关系IsMemberOf</code>的实化。]]
{{tsl|en|Conceptual model (computer science)|概念建模}}中广泛使用了实化。<ref>Antoni Olivé, Conceptual Modeling of Information Systems, Springer Verlag, 2007.</ref>实化一个关系(relationship)意味着把它视作一个实体。实化一个关系的目的是令其显式,必要时可以增加额外的信息。例如,关系''<code>IsMemberOf(member:Person, Committee)</code>''表示某人是某委员会的成员。下图左侧用表的形式列出了人''P1''是委员会''C1''与''C2''的成员;人''P2''是委员会''C1''成员。[[File:reification example1.png|500px|thumb|Example population of <code>关系IsMemberOf</code>的实化。]]
这一关系,也可看作实体。见图示的右侧。称作该实体实化了这个关系。这个实体类型为<code>Membership</code>。现在,可以给这个关系实体增加新的信息,如某人属于某委员会是由谁来提名加入的,可表示为''<code>IsNominatedBy(Membership, Person)</code>''。
这一关系,也可看作实体。见图示的右侧。称作该实体实化了这个关系。这个实体类型为<code>Membership</code>。现在,可以给这个关系实体增加新的信息,如某人属于某委员会是由谁来提名加入的,可表示为''<code>IsNominatedBy(Membership, Person)</code>''。


第24行: 第28行:


== 实化在UML中 ==
== 实化在UML中 ==
[[File:reification example2.png|400px|left|thumb|UML的[[类图]]表示Membership关系例子。]]
[[File:reification example2.png|400px|thumb|UML的[[类图]]表示Membership关系例子。]]


[[UML]]提供了关联类(association class)用于构建被实化的关系类型。关联类既是关联又是类。<ref>''Unified Modeling Language, UML superstructure'', Object Management Group, 2007-11-02.</ref>
[[UML]]提供了关联类(association class)用于构建被实化的关系类型。关联类既是关联又是类。<ref>''Unified Modeling Language, UML superstructure'', Object Management Group, 2007-11-02.</ref>
{{transH}}
== Reification on Semantic Web ==


=== RDF and OWL ===
In [[Semantic Web]] languages, such as [[Resource Description Framework]] (RDF) and [[Web Ontology Language]] (OWL), a statement is a binary relation. It is used to link two individuals or an individual and a value. Applications sometimes need to describe other RDF statements, for instance, to record information like when statements were made, or who made them, which is sometimes called "[[provenance]]" information. As an example, we may want to represent properties of a relation, such as our certainty about it, severity or strength of a relation, relevance of a relation, and so on.

The example from the conceptual modeling section describes a particular person with <code>URIref person:p1</code>, who is a member of the <code>committee:c1</code>. The RDF triple from that description is
<source lang="sparql">
person:p1 committee:isMemberOf committee:c1 .
</source>
Consider to store two further facts: (i) to record who nominated this particular person to this committee (a statement about the membership itself), and (ii) to record who added the fact to the database (a statement about the statement).

The first case is a case of classical reification like above in UML: reify the membership and store its attributes and roles etc.:

<source lang="sparql">
committee:Membership rdf:type owl:Class .
committee:membership12345 rdf:type committee:Membership .
committee:membership12345 committee:ofPerson person:p1 .
committee:membership12345 committee:inCommittee committee:c1 .
person:p2 committee:nominated committee:membership12345 .
</source>

Additionally, RDF provides a built-in vocabulary intended for describing RDF statements. A description of a statement using this vocabulary is called a reification of the statement. The RDF reification vocabulary consists of the type <code>rdf:Statement</code>, and the properties <code>rdf:subject</code>, <code>rdf:predicate</code>, and <code>rdf:object</code>.<ref name="rdf">{{cite web|url=http://www.w3.org/TR/2004/REC-rdf-primer-20040210/#reification |title=RDF Primer |publisher=W3.org |date= |accessdate=2010-10-09}}</ref>

Using the reification vocabulary, a reification of the statement about the person's membership would be given by assigning the statement a URIref such as <code>committee:membership12345</code> so that describing statements can be written as follows:
<source lang="sparql">
committee:membership12345Stat rdf:type rdf:Statement .
committee:membership12345Stat rdf:subject person:p1 .
committee:membership12345Stat rdf:predicate committee:isMemberOf .
committee:membership12345Stat rdf:object committee:c1 .
</source>
These statements say that the resource identified by the <code>URIref committee:membership12345Stat</code> is an RDF statement, that the subject of the statement refers to the resource identified by <code>person:p1</code>, the predicate of the statement refers to the resource identified by <code>committee:isMemberOf</code>, and the object of the statement refers to the resource <code>committee:c1</code>. Assuming that the original statement is actually identified by <code>committee:membership12345</code>, it should be clear by comparing the original statement with the reification that the reification actually does describe it. The conventional use of the RDF reification vocabulary always involves describing a statement using four statements in this pattern. Therefore, they are sometimes referred to as the "reification quad".<ref name="rdf"/>

Using reification according to this convention, we could record the fact that <code>person:p3</code> added the statement to the
database by
<source lang="sparql">
person:p3 committee:addedToDatabase committee:membership12345Stat .
</source>
It is important to note that in the conventional use of reification, the subject of the reification triples is assumed to identify a particular instance of a triple in a particular RDF document, rather than some arbitrary triple having the same subject, predicate, and object. This particular convention is used because reification is intended for expressing properties such as dates of composition and source information, as in the examples given already, and these properties need to be applied to specific instances of triples.
Note that the described triple <code>(subject predicate object)</code> itself is not implied by such a reification quad (and it is not necessary that it actually exists in the database). This allows also to use this mechanism to express which triples do ''not'' hold.

The power of the reification vocabulary in RDF is restricted by the lack of a built-in means for assigning URIrefs to statements, so in order to express "provenance" information of this kind in RDF, one has to use some mechanism (outside of RDF) to assign URIs to individual RDF statements, then make further statements about those individual statements, using their URIs to identify them.<ref name="rdf"/>

=== Reification in Topic Maps ===
In an [[Topic Maps|XML Topic Map]] (XTM), only a topic can have a name or play a role in an association. One may use an association to make an assertion about a topic, but one cannot directly make assertions about that assertion. However, it is possible to create a topic that reifies a non-topic construct in a map, thus enabling the association to be named and treated as a topic itself.<ref>[http://www.techquila.com/practical_intro.html Practical Introduction into Topic Maps] {{webarchive|url=https://web.archive.org/web/20090203202441/http://techquila.com/practical_intro.html |date=2009-02-03 }}.</ref>

=== Reification and n-ary relations ===
In Semantic Web languages, such as RDF and OWL, a property is a binary relation used to link two individuals or an individual and a value. However, in some cases, the natural and convenient way to represent certain concepts is to use relations to link an individual to more than just one individual or value. These relations are called [[n-ary relations]]. Examples are representing relations among multiple individuals, such as a committee, a person who is a committee member and another person who has nominated the first person to become the committee member, or a buyer, a seller, and an object that was bought when describing a purchase of a book.

A more general approach to reification is to create an explicit new class and n new properties to represent an n-ary relation, making an instance of the relation linking the n individuals an instance of this class. This approach can also be used to represent provenance information and other properties for an individual relation instance.<ref>{{cite web|url=http://www.w3.org/TR/swbp-n-aryRelations/ |title=W3C Defining N-ary relations on Semantic Web |publisher=W3.org |date= |accessdate=2010-10-09}}</ref>

:p1
a :Person ;
:has_membership _:membership_12345 .
_:membership_12345
a :Membership ;
:committee :c1;
:nominated_by :p2 .

=== Reification vs. quotation ===
It is also important to note that the reification described here is not the same as "quotation" found in other languages. Instead, the reification describes the relationship between a particular instance of a triple and the resources the triple refers to. The reification can be read intuitively as saying "this RDF triple talks about these things", rather than (as in quotation) "this RDF triple has this form." For instance, in the reification example used in this section, the triple:
<source lang="sparql">
committee:membership12345 rdf:subject person:p1 .
</source>
describing the <code>rdf:subject</code> of the original statement says that the subject of the statement is the resource (the person) identified by the URIref <code>person:p1</code>. It does not state that the subject of the statement is the URIref itself (i.e., a string beginning with certain characters), as quotation would.
{{transF}}
==参见==
==参见==
{{Wiktionary|reification}}
{{Wiktionary|reification}}
第101行: 第40行:
==参考文献==
==参考文献==
{{reflist}}
{{reflist}}

{{编程范型}}
[[Category:计算机编程]]
[[Category:计算机编程]]
[[Category:知识表示]]
[[Category:知识表示]]

2024年2月10日 (六) 13:45的最新版本

计算机科学中,实化(英語:reification)是把抽象的想法(idea)转化为明确的数据模型程序设计语言创建的其他对象的过程。通过实化,以前是隐式的、未表示的、可能是不可表示的被显式形成可概念(逻辑或计算)操作的。非正式地,实化也常被称作在特定系统范围内把某些东西变为“头等公民”即物件化。 实化是概念分析知识表示中最常用的技术。

在程序设计语言中的实化与反射

[编辑]

在程序设计语言中,把用户程序或者程序设计语言某一部分本来在编译期运行期是隐式的,表示为语言自身,这一过程称为实化。这使得其对程序可当作普通数据来利用。在具有反射的程序设计语言中,实化的数据表示了相关的被实化的领域。实化的数据常被称作头等对象

数据实化

[编辑]

数据实化涉及在形式规范英语formal specification中找到抽象数据类型的更为具体的表示。 [4] 例如,抽象数据类型集合(set)可以用map或者array来实化。

概念建模中的实化

[编辑]

概念建模英语Conceptual model (computer science)中广泛使用了实化。[5]实化一个关系(relationship)意味着把它视作一个实体。实化一个关系的目的是令其显式,必要时可以增加额外的信息。例如,关系IsMemberOf(member:Person, Committee)表示某人是某委员会的成员。下图左侧用表的形式列出了人P1是委员会C1C2的成员;人P2是委员会C1成员。

Example population of 关系IsMemberOf的实化。

这一关系,也可看作实体。见图示的右侧。称作该实体实化了这个关系。这个实体类型为Membership。现在,可以给这个关系实体增加新的信息,如某人属于某委员会是由谁来提名加入的,可表示为IsNominatedBy(Membership, Person)

与其密切相关的用法见实化 (知识表示)英语Reification (knowledge representation)

实化在UML中

[编辑]
UML的类图表示Membership关系例子。

UML提供了关联类(association class)用于构建被实化的关系类型。关联类既是关联又是类。[6]

参见

[编辑]

参考文献

[编辑]
  1. ^ The Java Language Specification, section 4.7页面存档备份,存于互联网档案馆), Java SE 7 Edition
  2. ^ Smalltalk Blocks And Closures. C2.com. 2009-10-15 [2010-10-09]. (原始内容存档于2010-02-06). 
  3. ^ J. Malenfant, M. Jacques and F.-N. Demers, A Tutorial on Behavioral Reflection and its Implementation页面存档备份,存于互联网档案馆
  4. ^ Formal Methods Europe, Frequently Asked Questions, part 13页面存档备份,存于互联网档案馆).
  5. ^ Antoni Olivé, Conceptual Modeling of Information Systems, Springer Verlag, 2007.
  6. ^ Unified Modeling Language, UML superstructure, Object Management Group, 2007-11-02.