Не обязательно лучше, но так как хорошо иметь варианты, вот как это сделать, используя заявления Jinja :
- debug:
msg: "{% for address in network.addresses.private_man %}\
{% if address.type == 'fixed' %}\
{{ address.addr }}\
{% endif %}\
{% endfor %}"
Или, если вы предпочитаете ставить все на одном line:
- debug:
msg: "{% for address in network.addresses.private_man if address.type == 'fixed' %}{{ address.addr }}{% endfor %}"
Возврат:
ok: [localhost] => {
"msg": "172.16.1.100"
}
Поскольку синтаксис SPARQL был сконструирован так, чтобы выглядеть как синтаксис Turtle (и наоборот), при построении запросов SPARQL часто полезно просматривать ваши данные в Turtle. Этот RDF / XML -
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE rdf:RDF><rdf:RDF xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:ns1="http://purl.org/ontology/mo/" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<ns1:MusicArtist rdf:about="http://dbtune.org/jamendo/artist/5655">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
<owl:sameAs rdf:resource="http://zitgist.com/music/artist/b8b40a3c-91c0-413b-a4f9-194ef0c7151a"/>
<foaf:based_near rdf:resource="http://sws.geonames.org/2802361/"/>
<foaf:homepage rdf:resource="http://cartonpate.com"/>
<foaf:img rdf:resource="http://img.jamendo.com/artists/c/carton.jpg"/>
<foaf:made rdf:resource="http://dbtune.org/jamendo/record/4957"/>
<foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Carton</foaf:name>
</ns1:MusicArtist>
</rdf:RDF>
- говорит то же самое, что и эта черепаха -
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
PREFIX owl: <http://www.w3.org/2002/07/owl#> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://dbtune.org/jamendo/artist/5655>
a <http://purl.org/ontology/mo/MusicArtist>,
rdfs:Resource ;
owl:sameAs <http://zitgist.com/music/artist/b8b40a3c-91c0-413b-a4f9-194ef0c7151a> ;
foaf:based_near <http://sws.geonames.org/2802361/> ;
foaf:homepage <http://cartonpate.com> ;
foaf:img <http://img.jamendo.com/artists/c/carton.jpg> ;
foaf:made <http://dbtune.org/jamendo/record/4957> ;
foaf:name "Carton"^^xsd:string .
- поэтому ваш запрос SPARQL должен быть (по модулю пробелы, каждый из которых может быть уменьшен до одного пробела) -
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT * WHERE { ?a a mo:MusicArtist ;
foaf:name "Carton"^^xsd:string }