How to Establish Relationships between rdfa lite n

2019-07-08 08:07发布

问题:

trying to semantically mark up a report page about specific addresses. The page provides a report about the address's energy consumption and presents offers for a service related to the energy consumption. I would like to semantically represent the place's address, the energy report related to the address, and offers that are available to the address. Right now, I have markup that has an RDFa lite node for place and another node for the offers. What is the best way to structure this to establish a relationship between these things, e.g., energy report and related offers for this place?

<!DOCTYPE html>
<html version="HTML+RDFa 1.1" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Energy Report For 1 main st, townville, ca</title>
</head>
<body>
<div xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:gr="http://purl.org/goodrelations/v1#"
xmlns:pto="http://www.productontology.org/id/"
xmlns:foo="http://example.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">

<div vocab="http://schema.org/" typeof="Place" additionaltype="Offer"    resource="#energyreport">

<h1 property="name">Energy Assessment for <div property="address" resource="#address" typeof="PostalAddress">
<span property="streetAddress">1 main st.
</span> <span property="addressLocality">townville</span>,
<span property="addressRegion">ca</span></div></h1>
<span property="description">Energy Potential for 1 main st., townville, ca. Explore installation offers. Find the best choice for your home.
</span>
</div>
<div vocab="http://schema.org/" resource="#offer" typeof="Offer">
<!-- The offer to sell it -->   
<div about="#offer" >
<div property="name">Energy Offerings</div>
<div rel="gr:hasBusinessFunction" resource="http://purl.org/goodrelations/v1#Sell"></div>
<div rel="gr:includes">
<!-- The object --> 
<div about="#myObject" typeof="http://www.productontology.org/id/Energy">
<div rel="rdf:type" resource="http://purl.org/goodrelations/v1#SomeItems"></div>
<div property="gr:description" xml:lang="en">Offer Details For Premium Lease Option</div>
<div property="gr:name" xml:lang="en">Premium Lease</div>
</div>
</div>
<div rel="foaf:page" resource="http://URI_of_the_page_containing_the_offer"></div>
<div rel="gr:hasPriceSpecification">
<div typeof="gr:UnitPriceSpecification">
<span property="gr:hasCurrency" content="USD" datatype="xsd:string">$</span>
<span property="gr:hasCurrencyValue" datatype="xsd:float">2.5</span>     
</div>
</div>    
</div>
</div>
</div>
</body>

回答1:

<div vocab="http://schema.org/" typeof="Place" additionaltype="Offer"    resource="#energyreport">

First of all, the additionaltype attribute is not valid in HTML and should not be used. With RDFa, you can safely put multiple types in the typeof attribute, like this: typeof="Place Offer".

To complement what Joshua said (which is great), if you don't want to add a visible link, you can also use an invisible <link> element:

<link property="offer" href="#offer" />

Another to check your RDFa is RDFa / Play. More tools are available from RDFa.info's Tools.



回答2:

If you're not already, I suggest that you try out the W3C's RDFa 1.1 Distiller and Parser. You can copy in your RDFa and see the data that is produces. For instance, your current markup yields these triples:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix gr: <http://purl.org/goodrelations/v1#> .
@prefix pto: <http://www.productontology.org/id/> .
@prefix rdfa: <http://www.w3.org/ns/rdfa#> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<> rdfa:usesVocabulary schema: .

<#energyreport> a schema:Place;
    schema:address <#address>;
    schema:description """Energy Potential for 1 main st., townville, ca. Explore installation offers. Find the best choice for your home.
""";
    schema:name """Energy Assessment for 
1 main st.
 townville,
ca""" .

<#offer> a schema:Offer;
    gr:hasBusinessFunction gr:Sell;
    gr:hasPriceSpecification [ a gr:UnitPriceSpecification;
            gr:hasCurrency "USD"^^xsd:string;
            gr:hasCurrencyValue "2.5"^^xsd:float ];
    gr:includes <#myObject>;
    schema:name "Energy Offerings";
    foaf:page <http://URI_of_the_page_containing_the_offer> .

<#address> a schema:PostalAddress;
    schema:addressLocality "townville";
    schema:addressRegion "ca";
    schema:streetAddress """1 main st.
""" .

<#myObject> a gr:SomeItems,
        pto:Energy;
    gr:description "Offer Details For Premium Lease Option"@en;
    gr:name "Premium Lease"@en .

This means that you have a relatively easy to use tool for checking whether modifications to your markup produce the kinds of results that you're looking for. (You should also check whether or not the triples above accurately represent the data that you've attempted to represent so far.) I think there may be some issues with the data as it is now. For instance, did you actually intend that the report is a place, i.e., that:

#energyreport a schema:Place 

At any rate, to add a relationship between one thing and another, just add another link like you've done for things so far, but use the identifier of another resource. For instance, if you add

<a href="#offer" rel="hasOffer">an offer for this place</a>

to the div that describes #energyreport, so that you have:

Energy Assessment for 1 main st. townville, ca Energy Potential for 1 main st., townville, ca. Explore installation offers. Find the best choice for your home. an offer for this place

you'll get triples like:

<#energyreport> a schema:Place;
    schema:address <#address>;
    schema:description """Energy Potential for 1 main st., townville, ca. Explore installation offers. Find the best choice for your home.
""";
    schema:hasOffer <#offer>;
    schema:name """Energy Assessment for 
1 main st.
 townville,
ca""" .

which include the relationship that you wanted (modulo the particular URIs used):

<#energyreport> schema:hasOffer <#offer>