RDF XML
Ví dụ về tài liệu RDF
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:si="https://www.w3schools.com/rdf/">
<rdf:Description rdf:about="https://www.w3schools.com">
<si:title>W3Schools</si:title>
<si:author>Jan Egil Refsnes</si:author>
</rdf:Description>
</rdf:RDF>
RDF là gì?
- RDF là viết tắt của R esource D escription F ramework
- RDF là một khuôn khổ để mô tả các tài nguyên trên web
- RDF được thiết kế để máy tính đọc và hiểu
- RDF không được thiết kế để hiển thị cho mọi người
- RDF được viết bằng XML
- RDF là một phần của Hoạt động web ngữ nghĩa của W3C
- RDF là một Khuyến nghị của W3C từ ngày 10 tháng 2 năm 2004
RDF - Ví dụ về sử dụng
- Mô tả thuộc tính cho các mặt hàng mua sắm, chẳng hạn như giá cả và tình trạng còn hàng
- Mô tả lịch trình thời gian cho các sự kiện web
- Mô tả thông tin về các trang web (nội dung, tác giả, ngày tạo và sửa đổi)
- Mô tả nội dung và xếp hạng cho ảnh web
- Mô tả nội dung cho các công cụ tìm kiếm
- Mô tả thư viện điện tử
RDF được thiết kế để máy tính đọc
RDF được thiết kế để cung cấp một phương thức phổ biến để mô tả thông tin để các ứng dụng máy tính có thể đọc và hiểu được thông tin.
Mô tả RDF không được thiết kế để hiển thị trên web.
RDF được viết bằng XML
Các tài liệu RDF được viết bằng XML. Ngôn ngữ XML được RDF sử dụng được gọi là RDF / XML.
Bằng cách sử dụng XML, thông tin RDF có thể dễ dàng được trao đổi giữa các loại máy tính khác nhau sử dụng các loại hệ điều hành và ngôn ngữ ứng dụng khác nhau.
RDF và "Web ngữ nghĩa"
Ngôn ngữ RDF là một phần của Hoạt động Web Ngữ nghĩa của W3C. "Tầm nhìn web ngữ nghĩa" của W3C là một tương lai nơi:
- Thông tin web có ý nghĩa chính xác
- Thông tin web có thể được máy tính hiểu và xử lý
- Máy tính có thể tích hợp thông tin từ web
RDF sử dụng mã định danh Web (URI) để xác định tài nguyên.
RDF mô tả tài nguyên với các thuộc tính và giá trị thuộc tính.
Giá trị tài nguyên, thuộc tính và tài sản RDF
RDF xác định mọi thứ bằng cách sử dụng mã định danh Web (URI) và mô tả tài nguyên với các thuộc tính và giá trị thuộc tính.
Giải thích về giá trị tài nguyên, tài sản và tài sản:
- Tài nguyên là bất kỳ thứ gì có thể có URI, chẳng hạn như "https://www.w3schools.com/rdf"
- Thuộc tính là Tài nguyên có tên, chẳng hạn như "tác giả" hoặc "trang chủ"
- Giá trị Thuộc tính là giá trị của Thuộc tính, chẳng hạn như "Jan Egil Refsnes" hoặc "https://www.w3schools.com" (lưu ý rằng giá trị thuộc tính có thể là một tài nguyên khác)
Tài liệu RDF sau có thể mô tả tài nguyên "https://www.w3schools.com/rdf":
<?xml version="1.0"?>
<RDF>
<Description about="https://www.w3schools.com/rdf">
<author>Jan Egil Refsnes</author>
<homepage>https://www.w3schools.com</homepage>
</Description>
</RDF>
Ví dụ trên được đơn giản hóa. Không gian tên bị bỏ qua.
Tuyên bố RDF
Sự kết hợp của một giá trị Tài nguyên, một Thuộc tính và một Thuộc tính tạo thành một Câu lệnh (được gọi là chủ ngữ, vị từ và đối tượng của một Câu lệnh).
Hãy xem một số câu lệnh ví dụ để hiểu rõ hơn:
Tuyên bố: "Tác giả của https://www.w3schools.com/rdf là Jan Egil Refsnes".
- Chủ đề của tuyên bố trên là: https://www.w3schools.com/rdf
- Vị ngữ là: author
- Đối tượng là: Jan Egil Refsnes
Tuyên bố: "Trang chủ của https://www.w3schools.com/rdf là https://www.w3schools.com".
- Chủ đề của tuyên bố trên là: https://www.w3schools.com/rdf
- Vị ngữ là: trang chủ
- Đối tượng là: https://www.w3schools.com
Ví dụ về RDF
Đây là hai bản ghi từ danh sách CD:
Title | Artist | Country | Company | Price | Year |
---|---|---|---|---|---|
Empire Burlesque | Bob Dylan | USA | Columbia | 10.90 | 1985 |
Hide your heart | Bonnie Tyler | UK | CBS Records | 9.90 | 1988 |
Dưới đây là một vài dòng từ tài liệu RDF:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque">
<cd:artist>Bob Dylan</cd:artist>
<cd:country>USA</cd:country>
<cd:company>Columbia</cd:company>
<cd:price>10.90</cd:price>
<cd:year>1985</cd:year>
</rdf:Description>
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Hide your heart">
<cd:artist>Bonnie Tyler</cd:artist>
<cd:country>UK</cd:country>
<cd:company>CBS Records</cd:company>
<cd:price>9.90</cd:price>
<cd:year>1988</cd:year>
</rdf:Description>
.
.
.
</rdf:RDF>
Dòng đầu tiên của tài liệu RDF là khai báo XML. Khai báo XML được theo sau bởi phần tử gốc của tài liệu RDF: <rdf: RDF> .
Không gian tên xmlns: rdf , chỉ định rằng các phần tử có tiền tố rdf là từ không gian tên "http://www.w3.org/1999/02/22-rdf-syntax-ns#".
Không gian tên xmlns: cd , chỉ định rằng các phần tử có tiền tố cd là từ không gian tên "http: //www.recshop.fake/cd#".
Phần tử <rdf: Description> chứa mô tả của tài nguyên được xác định bởi thuộc tính rdf: about .
Các phần tử: <cd: artist>, <cd: country>, <cd: company>, v.v. là các thuộc tính của tài nguyên.
RDF Online Validator
Dịch vụ xác thực RDF của W3C rất hữu ích khi học RDF. Tại đây bạn có thể thử nghiệm với các tệp RDF.
Trình xác thực RDF trực tuyến phân tích cú pháp tài liệu RDF của bạn, kiểm tra cú pháp của bạn và tạo các dạng xem dạng bảng và đồ họa cho tài liệu RDF của bạn.
Sao chép và dán ví dụ dưới đây vào trình xác thực RDF của W3C:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:si="https://www.w3schools.com/rdf/">
<rdf:Description rdf:about="https://www.w3schools.com">
<si:title>W3Schools.com</si:title>
<si:author>Jan Egil Refsnes</si:author>
</rdf:Description>
</rdf:RDF>
Khi bạn phân tích cú pháp ví dụ trên, kết quả sẽ giống như thế này .
Phần tử RDF
Các phần tử chính của RDF là phần tử gốc, <RDF> và phần tử <Mô tả>, xác định một tài nguyên.
Phần tử <rdf: RDF>
<rdf: RDF> là phần tử gốc của tài liệu RDF. Nó định nghĩa tài liệu XML là tài liệu RDF. Nó cũng chứa một tham chiếu đến không gian tên RDF:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
...Description goes here...
</rdf:RDF>
Phần tử <rdf: Description>
Phần tử <rdf: Description> xác định tài nguyên bằng thuộc tính about.
Phần tử <rdf: Description> chứa các phần tử mô tả tài nguyên:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque">
<cd:artist>Bob Dylan</cd:artist>
<cd:country>USA</cd:country>
<cd:company>Columbia</cd:company>
<cd:price>10.90</cd:price>
<cd:year>1985</cd:year>
</rdf:Description>
</rdf:RDF>
Các yếu tố, nghệ sĩ, quốc gia, công ty, giá và năm, được xác định trong không gian tên http: //www.recshop.fake/cd#. Không gian tên này nằm ngoài RDF (và không phải là một phần của RDF). RDF chỉ định nghĩa khung. Các yếu tố, nghệ sĩ, quốc gia, công ty, giá cả và năm phải được xác định bởi người khác (công ty, tổ chức, cá nhân, v.v.).
Thuộc tính dưới dạng thuộc tính
Các phần tử thuộc tính cũng có thể được định nghĩa là các thuộc tính (thay vì các phần tử):
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque"
cd:artist="Bob Dylan" cd:country="USA"
cd:company="Columbia" cd:price="10.90"
cd:year="1985" />
</rdf:RDF>
Thuộc tính dưới dạng tài nguyên
Các phần tử thuộc tính cũng có thể được định nghĩa là tài nguyên:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque">
<cd:artist rdf:resource="http://www.recshop.fake/cd/dylan" />
...
...
</rdf:Description>
</rdf:RDF>
Trong ví dụ trên, thuộc tính nghệ sĩ không có giá trị mà là tham chiếu đến tài nguyên chứa thông tin về nghệ sĩ.
Vùng chứa RDF
Các thùng chứa RDF được sử dụng để mô tả nhóm sự vật.
Các phần tử RDF sau được sử dụng để mô tả các nhóm: <Bag>, <Seq> và <Alt>.
Phần tử <rdf: Bag>
Phần tử <rdf: Bag> được sử dụng để mô tả danh sách các giá trị không nhất thiết phải theo một thứ tự cụ thể.
Phần tử <rdf: Bag> có thể chứa các giá trị trùng lặp.
Thí dụ
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Beatles">
<cd:artist>
<rdf:Bag>
<rdf:li>John</rdf:li>
<rdf:li>Paul</rdf:li>
<rdf:li>George</rdf:li>
<rdf:li>Ringo</rdf:li>
</rdf:Bag>
</cd:artist>
</rdf:Description>
</rdf:RDF>
Phần tử <rdf: Seq>
Phần tử <rdf: Seq> được sử dụng để mô tả danh sách các giá trị có thứ tự (Ví dụ: theo thứ tự bảng chữ cái).
Phần tử <rdf: Seq> có thể chứa các giá trị trùng lặp.
Thí dụ
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Beatles">
<cd:artist>
<rdf:Seq>
<rdf:li>George</rdf:li>
<rdf:li>John</rdf:li>
<rdf:li>Paul</rdf:li>
<rdf:li>Ringo</rdf:li>
</rdf:Seq>
</cd:artist>
</rdf:Description>
</rdf:RDF>
Phần tử <rdf: Alt>
Phần tử <rdf: Alt> được sử dụng để mô tả danh sách các giá trị thay thế (người dùng chỉ có thể chọn một trong các giá trị).
Thí dụ
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Beatles">
<cd:format>
<rdf:Alt>
<rdf:li>CD</rdf:li>
<rdf:li>Record</rdf:li>
<rdf:li>Tape</rdf:li>
</rdf:Alt>
</cd:format>
</rdf:Description>
</rdf:RDF>
Điều khoản RDF
Trong các ví dụ trên, chúng ta đã nói về "danh sách các giá trị" khi mô tả các phần tử vùng chứa. Trong RDF "danh sách các giá trị" này được gọi là thành viên.
Vì vậy, chúng tôi có những điều sau:
- Container là một tài nguyên chứa những thứ
- Những thứ được chứa được gọi là thành viên (không phải danh sách các giá trị)
Bộ sưu tập RDF
Bộ sưu tập RDF mô tả các nhóm CHỈ có thể chứa các thành viên được chỉ định.
Thuộc tính rdf: parseType = "Collection"
Như đã thấy trong chương trước, một vùng chứa nói rằng các tài nguyên chứa là thành viên - nó không nói rằng các thành viên khác không được phép.
Bộ sưu tập RDF được sử dụng để mô tả các nhóm CHỈ có thể chứa các thành viên được chỉ định.
Một bộ sưu tập được mô tả bởi thuộc tính rdf: parseType = "Bộ sưu tập".
Thí dụ
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://recshop.fake/cd#">
<rdf:Description
rdf:about="http://recshop.fake/cd/Beatles">
<cd:artist rdf:parseType="Collection">
<rdf:Description rdf:about="http://recshop.fake/cd/Beatles/George"/>
<rdf:Description rdf:about="http://recshop.fake/cd/Beatles/John"/>
<rdf:Description rdf:about="http://recshop.fake/cd/Beatles/Paul"/>
<rdf:Description rdf:about="http://recshop.fake/cd/Beatles/Ringo"/>
</cd:artist>
</rdf:Description>
</rdf:RDF>
Lược đồ RDF và các lớp ứng dụng
Lược đồ RDF (RDFS) là một phần mở rộng của RDF.
RDF mô tả tài nguyên với các lớp, thuộc tính và giá trị.
Ngoài ra, RDF cũng cần một cách để xác định các lớp và thuộc tính dành riêng cho ứng dụng. Các lớp và thuộc tính dành riêng cho ứng dụng phải được xác định bằng cách sử dụng các phần mở rộng cho RDF.
Một phần mở rộng như vậy là Lược đồ RDF.
Lược đồ RDF (RDFS)
Lược đồ RDF không cung cấp các lớp và thuộc tính dành riêng cho ứng dụng thực tế.
Thay vào đó, Lược đồ RDF cung cấp khung để mô tả các lớp và thuộc tính dành riêng cho ứng dụng.
Classes in RDF Schema are much like classes in object oriented programming languages. This allows resources to be defined as instances of classes, and subclasses of classes.
RDFS Example
The following example demonstrates some of the RDFS facilities:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://www.animals.fake/animals#">
<rdf:Description rdf:ID="animal">
<rdf:type
rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
</rdf:Description>
<rdf:Description rdf:ID="horse">
<rdf:type
rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<rdfs:subClassOf rdf:resource="#animal"/>
</rdf:Description>
</rdf:RDF>
In the example above, the resource "horse" is a subclass of the class "animal".
Example Abbreviated
Since an RDFS class is an RDF resource we can abbreviate the example above by using rdfs:Class instead of rdf:Description, and drop the rdf:type information:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://www.animals.fake/animals#">
<rdfs:Class rdf:ID="animal" />
<rdfs:Class rdf:ID="horse">
<rdfs:subClassOf rdf:resource="#animal"/>
</rdfs:Class>
</rdf:RDF>
That's it!
The Dublin Core
The Dublin Core Metadata Initiative (DCMI) has created some predefined properties for describing documents.
RDF is metadata (data about data). RDF is used to describe information resources.
The Dublin Core is a set of predefined properties for describing documents.
The first Dublin Core properties were defined at the Metadata Workshop in Dublin, Ohio in 1995 and is currently maintained by the Dublin Core Metadata Initiative.
Property | Definition |
---|---|
Contributor | An entity responsible for making contributions to the content of the resource |
Coverage | The extent or scope of the content of the resource |
Creator | An entity primarily responsible for making the content of the resource |
Format | The physical or digital manifestation of the resource |
Date | A date of an event in the lifecycle of the resource |
Description | An account of the content of the resource |
Identifier | An unambiguous reference to the resource within a given context |
Language | A language of the intellectual content of the resource |
Publisher | An entity responsible for making the resource available |
Relation | A reference to a related resource |
Rights | Information about rights held in and over the resource |
Source | A Reference to a resource from which the present resource is derived |
Subject | A topic of the content of the resource |
Title | A name given to the resource |
Type | The nature or genre of the content of the resource |
A quick look at the table above indicates that RDF is ideal for representing Dublin Core information.
RDF Example
The following example demonstrates the use of some of the Dublin Core properties in an RDF document:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc= "http://purl.org/dc/elements/1.1/">
<rdf:Description rdf:about="https://www.w3schools.com">
<dc:description>W3Schools - Free tutorials</dc:description>
<dc:publisher>Refsnes Data as</dc:publisher>
<dc:date>2008-09-01</dc:date>
<dc:type>Web Development</dc:type>
<dc:format>text/html</dc:format>
<dc:language>en</dc:language>
</rdf:Description>
</rdf:RDF>
RDF Reference
The RDF namespace (xmlns:rdf) is: http://www.w3.org/1999/02/22-rdf-syntax-ns#
The RDFS namespace (xmlns:rdfs ) is: http://www.w3.org/2000/01/rdf-schema#
The recommended file extension for RDF files is .rdf. However, the extension .xml is often used to provide compatibility with old xml parsers.
The MIME type should be "application/rdf+xml".
RDFS / RDF Classes
Element | Class of | Subclass of |
---|---|---|
rdfs:Class | All classes | |
rdfs:Datatype | Data types | Class |
rdfs:Resource | All resources | Class |
rdfs:Container | Containers | Resource |
rdfs:Literal | Literal values (text and numbers) | Resource |
rdf:List | Lists | Resource |
rdf:Property | Properties | Resource |
rdf:Statement | Statements | Resource |
rdf:Alt | Containers of alternatives | Container |
rdf:Bag | Unordered containers | Container |
rdf:Seq | Ordered containers | Container |
rdfs:ContainerMembershipProperty | Container membership properties | Property |
rdf:XMLLiteral | XML literal values | Literal |
RDFS / RDF Properties
Element | Domain | Range | Description |
---|---|---|---|
rdfs:domain | Property | Class | The domain of the resource |
rdfs:range | Property | Class | The range of the resource |
rdfs:subPropertyOf | Property | Property | The property is a sub property of a property |
rdfs:subClassOf | Class | Class | The resource is a subclass of a class |
rdfs:comment | Resource | Literal | The human readable description of the resource |
rdfs:label | Resource | Literal | The human readable label (name) of the resource |
rdfs:isDefinedBy | Resource | Resource | The definition of the resource |
rdfs:seeAlso | Resource | Resource | The additional information about the resource |
rdfs:member | Resource | Resource | The member of the resource |
rdf:first | List | Resource | |
rdf:rest | List | List | |
rdf:subject | Statement | Resource | The subject of the resource in an RDF Statement |
rdf:predicate | Statement | Resource | The predicate of the resource in an RDF Statement |
rdf:object | Statement | Resource | The object of the resource in an RDF Statement |
rdf:value | Resource | Resource | The property used for values |
rdf:type | Resource | Class | The resource is an instance of a class |
RDF Attributes
Attribute | Description |
---|---|
rdf:about | Defines the resource being described |
rdf:Description | Container for the description of a resource |
rdf:resource | Defines a resource to identify a property |
rdf:datatype | Defines the data type of an element |
rdf:ID | Defines the ID of an element |
rdf:li | Defines a list |
rdf:_n | Defines a node |
rdf:nodeID | Defines the ID of an element node |
rdf:parseType | Defines how an element should be parsed |
rdf:RDF | The root of an RDF document |
xml:base | Defines the XML base |
xml:lang | Defines the language of the element content |