XML RDF
ตัวอย่างเอกสาร 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 คืออะไร?
- RDF ย่อมาจากR esource D escription F ramework
- RDF เป็นเฟรมเวิร์กสำหรับการอธิบายทรัพยากรบนเว็บ
- RDF ออกแบบมาเพื่อให้คอมพิวเตอร์อ่านและเข้าใจได้
- RDF ไม่ได้ออกแบบมาเพื่อแสดงต่อผู้คน
- RDF เขียนด้วย XML
- RDF เป็นส่วนหนึ่งของ Semantic Web Activity ของ W3C
- RDF เป็นคำแนะนำของ W3C ตั้งแต่วันที่ 10 กุมภาพันธ์ พ.ศ. 2547
RDF - ตัวอย่างการใช้งาน
- อธิบายคุณสมบัติสำหรับรายการช้อปปิ้ง เช่น ราคาและจำนวนห้องว่าง
- อธิบายตารางเวลาสำหรับกิจกรรมบนเว็บ
- อธิบายข้อมูลเกี่ยวกับหน้าเว็บ (เนื้อหา ผู้แต่ง วันที่สร้างและแก้ไข)
- อธิบายเนื้อหาและการให้คะแนนสำหรับรูปภาพบนเว็บ
- อธิบายเนื้อหาสำหรับเครื่องมือค้นหา
- บรรยายห้องสมุดอิเล็กทรอนิกส์
RDF ออกแบบมาเพื่อให้คอมพิวเตอร์อ่านได้
RDF ได้รับการออกแบบเพื่อให้เป็นวิธีการทั่วไปในการอธิบายข้อมูล เพื่อให้สามารถอ่านและทำความเข้าใจได้โดยโปรแกรมคอมพิวเตอร์
คำอธิบาย RDF ไม่ได้ออกแบบมาเพื่อแสดงบนเว็บ
RDF เขียนด้วย XML
เอกสาร RDF เขียนในรูปแบบ XML ภาษา XML ที่ใช้โดย RDF เรียกว่า RDF/XML
ด้วยการใช้ XML ข้อมูล RDF สามารถแลกเปลี่ยนระหว่างคอมพิวเตอร์ประเภทต่างๆ ได้อย่างง่ายดายโดยใช้ระบบปฏิบัติการประเภทต่างๆ และภาษาของแอปพลิเคชัน
RDF และ "เว็บความหมาย"
ภาษา RDF เป็นส่วนหนึ่งของ Semantic Web Activity ของ W3C "Semantic Web Vision" ของ W3C เป็นอนาคตที่:
- ข้อมูลเว็บมีความหมายที่แน่นอน
- คอมพิวเตอร์สามารถเข้าใจและประมวลผลข้อมูลเว็บได้
- คอมพิวเตอร์สามารถรวมข้อมูลจากเว็บได้
RDF ใช้ตัวระบุเว็บ (URI) เพื่อระบุทรัพยากร
RDF อธิบายทรัพยากรด้วยคุณสมบัติและค่าคุณสมบัติ
RDF ทรัพยากร ทรัพย์สิน และมูลค่าทรัพย์สิน
RDF ระบุสิ่งต่าง ๆ โดยใช้ตัวระบุเว็บ (URI) และอธิบายทรัพยากรด้วยคุณสมบัติและค่าคุณสมบัติ
คำอธิบายของทรัพยากร ทรัพย์สิน และมูลค่าทรัพย์สิน:
- ทรัพยากร คือ สิ่งที่สามารถมี URI ได้ เช่น "https://www.w3schools.com/rdf"
- คุณสมบัติ คือทรัพยากร ที่มีชื่อ เช่น "ผู้แต่ง" หรือ "โฮมเพจ"
- มูลค่าทรัพย์สินคือมูลค่าของทรัพย์สิน เช่น "Jan Egil Refsnes" หรือ "https://www.w3schools.com" (โปรดทราบว่ามูลค่าทรัพย์สินอาจเป็นทรัพยากรอื่นได้)
เอกสาร RDF ต่อไปนี้สามารถอธิบายทรัพยากร "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>
ตัวอย่างข้างต้นเป็นแบบง่าย เนมสเปซถูกละเว้น
คำชี้แจง RDF
การรวมกันของทรัพยากร คุณสมบัติ และมูลค่าทรัพย์สินก่อให้เกิดคำชี้แจง (เรียกว่าประธาน ภาคแสดง และวัตถุของคำชี้แจง)
มาดูตัวอย่างข้อความเพื่อความเข้าใจที่ดีขึ้น:
คำชี้แจง: "ผู้เขียน https://www.w3schools.com/rdf คือ Jan Egil Refsnes"
- หัวข้อของข้อความข้างต้นคือ: https://www.w3schools.com/rdf
- ภาคแสดงคือ: ผู้แต่ง
- วัตถุคือ: Jan Egil Refsnes
คำชี้แจง: "หน้าแรกของ https://www.w3schools.com/rdf คือ https://www.w3schools.com"
- หัวข้อของข้อความข้างต้นคือ: https://www.w3schools.com/rdf
- เพรดิเคตคือ: หน้าแรก
- วัตถุคือ: https://www.w3schools.com
ตัวอย่าง RDF
นี่คือสองบันทึกจากรายการซีดี:
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 |
ด้านล่างนี้คือสองสามบรรทัดจากเอกสาร 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>
บรรทัดแรกของเอกสาร RDF คือการประกาศ XML การประกาศ XML ตามด้วยองค์ประกอบรากของเอกสาร RDF: <rdf:RDF >
เนมส เป ซ xmlns:rdfระบุว่าองค์ประกอบที่มีคำนำหน้า rdf มาจากเนมสเปซ "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
เนมส เป ซ xmlns:cdระบุว่าองค์ประกอบที่มีคำนำหน้า cd มาจากเนมสเปซ "http://www.recshop.fake/cd#"
<rdf:Description>องค์ประกอบประกอบด้วยคำอธิบายของทรัพยากรที่ระบุโดยแอตทริบิวต์rdf:about
องค์ประกอบ: <cd:artist>, <cd:country>, <cd:company>ฯลฯ เป็นคุณสมบัติของทรัพยากร
โปรแกรมตรวจสอบ RDF ออนไลน์
บริการตรวจสอบ RDF ของ W3Cมีประโยชน์เมื่อเรียนรู้ RDF คุณสามารถทดลองกับไฟล์ RDF ได้ที่นี่
โปรแกรมตรวจสอบ RDF ออนไลน์จะแยกวิเคราะห์เอกสาร RDF ของคุณ ตรวจสอบไวยากรณ์ และสร้างมุมมองแบบตารางและแบบกราฟิกของเอกสาร RDF ของคุณ
คัดลอกและวางตัวอย่างด้านล่างลงในตัวตรวจสอบ RDF ของ 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>
เมื่อคุณแยกวิเคราะห์ตัวอย่างด้านบน ผลลัพธ์จะ ออกมา ประมาณ นี้
องค์ประกอบ RDF
องค์ประกอบหลักของ RDF คือองค์ประกอบราก <RDF> และองค์ประกอบ <Description> ซึ่งระบุทรัพยากร
<rdf:RDF> องค์ประกอบ
<rdf:RDF> เป็นองค์ประกอบรากของเอกสาร RDF กำหนดเอกสาร XML ให้เป็นเอกสาร RDF นอกจากนี้ยังมีการอ้างอิงถึงเนมสเปซ RDF:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
...Description goes here...
</rdf:RDF>
<rdf:Description> องค์ประกอบ
<rdf:Description> องค์ประกอบระบุทรัพยากรที่มีคุณสมบัติเกี่ยวกับ
<rdf:Description> องค์ประกอบประกอบด้วยองค์ประกอบที่อธิบายทรัพยากร:
<?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>
องค์ประกอบ ศิลปิน ประเทศ บริษัท ราคา และปี มีการกำหนดไว้ใน http://www.recshop.fake/cd# เนมสเปซ เนมสเปซนี้อยู่นอก RDF (และไม่ใช่ส่วนหนึ่งของ RDF) 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:country="USA"
cd:company="Columbia" cd:price="10.90"
cd:year="1985" />
</rdf: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 rdf:resource="http://www.recshop.fake/cd/dylan" />
...
...
</rdf:Description>
</rdf:RDF>
ในตัวอย่างข้างต้น ศิลปินอสังหาริมทรัพย์ไม่มีค่า แต่มีการอ้างอิงถึงแหล่งข้อมูลที่มีข้อมูลเกี่ยวกับศิลปิน
คอนเทนเนอร์ RDF
คอนเทนเนอร์ RDF ใช้เพื่ออธิบายกลุ่มของสิ่งต่างๆ
อิลิเมนต์ RDF ต่อไปนี้ใช้เพื่ออธิบายกลุ่ม: <Bag>, <Seq> และ <Alt>
<rdf:Bag> องค์ประกอบ
<rdf:Bag> องค์ประกอบใช้เพื่ออธิบายรายการค่าที่ไม่จำเป็นต้องอยู่ในลำดับเฉพาะ
<rdf:Bag> องค์ประกอบอาจมีค่าที่ซ้ำกัน
ตัวอย่าง
<?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>
<rdf:Seq> องค์ประกอบ
<rdf:Seq> องค์ประกอบใช้เพื่ออธิบายรายการค่าที่เรียงลำดับ (ตัวอย่างเช่น ตามลำดับตัวอักษร)
<rdf:Seq> องค์ประกอบอาจมีค่าที่ซ้ำกัน
ตัวอย่าง
<?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>
<rdf:Alt> องค์ประกอบ
องค์ประกอบ <rdf:Alt> ใช้เพื่ออธิบายรายการค่าทางเลือก (ผู้ใช้สามารถเลือกค่าได้เพียงค่าเดียว)
ตัวอย่าง
<?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>
ข้อกำหนด RDF
ในตัวอย่างข้างต้น เราได้พูดถึง "รายการค่า" เมื่ออธิบายองค์ประกอบของคอนเทนเนอร์ ใน RDF "รายการค่า" เหล่านี้เรียกว่าสมาชิก
ดังนั้นเราจึงมีสิ่งต่อไปนี้:
- คอนเทนเนอร์คือทรัพยากรที่บรรจุสิ่งของต่างๆ
- สิ่งที่มีอยู่เรียกว่าสมาชิก (ไม่ใช่รายการค่า)
คอลเลกชัน RDF
คอลเล็กชัน RDF อธิบายกลุ่มที่มีได้เฉพาะสมาชิกที่ระบุเท่านั้น
rdf:parseType="Collection" Attribute
ตามที่เห็นในบทที่แล้ว คอนเทนเนอร์บอกว่าทรัพยากรที่บรรจุนั้นเป็นสมาชิก - ไม่ได้บอกว่าไม่อนุญาตให้ใช้สมาชิกคนอื่น
คอลเล็กชัน RDF ใช้เพื่ออธิบายกลุ่มที่มีได้เฉพาะสมาชิกที่ระบุเท่านั้น
คอลเล็กชันถูกอธิบายโดยแอตทริบิวต์ rdf:parseType="Collection"
ตัวอย่าง
<?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>
RDF Schema และคลาสแอปพลิเคชัน
RDF Schema (RDFS) เป็นส่วนขยายของ RDF
RDF อธิบายทรัพยากรด้วยคลาส คุณสมบัติ และค่า
นอกจากนี้ RDF ยังต้องการวิธีกำหนดคลาสและคุณสมบัติเฉพาะแอปพลิเคชัน ต้องกำหนดคลาสและคุณสมบัติเฉพาะแอปพลิเคชันโดยใช้ส่วนขยายเป็น RDF
หนึ่งในส่วนขยายดังกล่าวคือ RDF Schema
สคีมา RDF (RDFS)
RDF Schema ไม่ได้จัดเตรียมคลาสและคุณสมบัติเฉพาะแอปพลิเคชันจริง
RDF Schema ให้กรอบงานเพื่ออธิบายคลาสและคุณสมบัติเฉพาะแอปพลิเคชันแทน
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 |