问题
I'd like to inventory my wine collection using RDF but am not sure how to specify that wine can contain percentages of several grape varietals. Below is an attempt to do so in Turtle syntax using rdf:bag.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix vin: <http://example.org/wine#> .
<http://example.org/wine/id#1001>
a <http://example.org/wine/ns#red> ;
vin:name "Quilceda Creek CVR" ;
vin:vintage "2014"^^xsd:gYear ;
vin:winery "Quilceda Creek"@en ;
vin:alcoholContent "0.15"^^xsd:decimal ;
vin:agedIn "French Oak"@en ;
vin:varietals rdf:_1, rdf:_2, rdf:_3, rdf:_4, [
a rdf:Bag ;
rdf:_1 "Cabernet Sauvignon"@en ;
rdf:_1 "0.76"^^xsd:decimal ;
rdf:_2 "Merlot"@en ;
rdf:_2 "0.20"^^xsd:decimal ;
rdf:_3 "Petit Verdot"@en ;
rdf:_3 "0.03"^^xsd:decimal ;
rdf:_4 "Malbec"@en ;
rdf:_4 "0.01"^^xsd:decimal ;
] .
When I convert this to XML/RDF, the triples with percentages get dropped. This makes me think you shouldn't/can't use the bag item predicates (ex. rdf:_1) more than once.
I've also considered making a bag of bags, with a bag for each varietal containing the name and percentage. This would involve creating even more blank nodes, which doesn't seem right to me. Eventually I would like to be able to retrieve all wines containing at least a certain percentage of a particular varietal. I'm not sure if I'll be able to if varietal name and percentage pairs have no relationship defined other than being in the same bag.
I'm new to this but have a feeling I need to look to RDF Schemas and ontologies for this problem. That said, I also don't want to jump ship to that until I totally understand why I need to.
If possible, how can RDF be used to represent that a wine has certain percentages of different varietals?
回答1:
I’d prefer to use this simple pattern:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#> .
@prefix vin: <http://example.org/wine#> .
vin:id1001 vin:varietal [ vin:grape wine:CabernetSauvignonGrape;
vin:percentage "0.76"^^xsd:decimal ] ;
vin:varietal [ vin:grape wine:MerlotGrape ;
vin:percentage "0.20"^^xsd:decimal ] .
Example SPARQL queries against the pattern above would be:
SELECT DISTINCT ?sophistique
WHERE {
?sophistique vin:varietal/vin:percentage ?percentage .
FILTER (?percentage <= "0.05"^^decimal)
}
SELECT DISTINCT ?coupage
WHERE {
?coupage vin:varietal/vin:grape ?grape1.
?coupage vin:varietal/vin:grape ?grape2.
FILTER (?grape1 != ?grape2)
}
SELECT ?id (("1.0"^^xsd:decimal - SUM(?percentage)) AS ?part_des_anges)
WHERE {
?id vin:varietal/vin:percentage ?percentage .
} GROUP BY ?id HAVING ( ?part_des_anges > "0.0"^^xsd:decimal )
Some remarks:
It is more ideologically correct to use, wherever possible, things instead of strings in RDF.
The W3C’s example wine ontology could provide URIs for many of these things.Why don’t you use just multiple occurrences of the
vin:varietal
property instead ofrdf:Seq
? It will be harder to deal withrdfs:Container
’s in SPARQL and especially in OWL.I don’t think these varietals (grape varieties with percentages) need strong identification with URIs, their “ontological status” are not sufficiently solid. Thus, I use blank nodes.
来源:https://stackoverflow.com/questions/44209860/what-rdf-patterns-can-be-used-to-represent-components-and-the-percentage-they-ma