def query_commanders():
    query = """
SELECT DISTINCT ?person, ?battle, ?surname, ?given, ?name WHERE {
    ?battle dbo:isPartOfMilitaryConflict dbr:American_Civil_War ;
    a dbo:MilitaryConflict .
    ?battle dbo:commander ?person .
    ?person a foaf:Person .
    OPTIONAL { ?person foaf:surname ?surname }
}
    """
    results = query_dbpedia(query)
    data = []
    for x in results['results']['bindings']:
        data.append(dict((k, x[k]['value']) for k in x))
    return data
Ejemplo n.º 2
0
def download():
    query = """
SELECT DISTINCT ?s WHERE {
  {?s dct:subject/skos:broader* dbc:Battles_of_the_American_Civil_War}
  UNION
  {?s dbo:isPartOfMilitaryConflict dbr:American_Civil_War ;
      a dbo:MilitaryConflict}
   FILTER (!regex(str(?s), "Never_Call_Retreat"))
}
"""
    results = query_dbpedia(query)
    resources = [x['s']['value'] for x in results['results']['bindings']]
    with open('dbpedia_conflicts.csv', 'w') as f:
        fields = ('uri', )
        writer = csv.DictWriter(f, fields)
        writer.writeheader()
        for s in resources:
            writer.writerow({'uri': s})
Ejemplo n.º 3
0
def query_category(category):
    results = query_dbpedia(CATEGORY_QUERY_TEMPLATE % category)
    return [x['unit']['value'] for x in results['results']['bindings']]
Ejemplo n.º 4
0
def query_category(category):
    results = query_dbpedia(CATEGORY_QUERY_TEMPLATE % category)
    return [x['ship']['value']
            for x in results['results']['bindings']]