import requests


def run_resource_query(resource_uri, prop):
    """
    Queries the KnowledgeStore for the given property of the given mention and returns a list of results.
    
    The function returns an empty list in case of invalid resource URI or invalid property.
    
    For the function call 'run_resource_query("http://en.wikinews.org/wiki/Mexican_president_defends_emigration", "dct:title")',
    the result looks like this:
    ['Mexican president defends emigration']
    """
    p = {"id":"<{0}>".format(resource_uri), "property":prop}
    req = requests.get('http://knowledgestore2.fbk.eu/nwr/wikinews/resources', params=p)
    json = req.json()
    result = []
    
    if '@graph' in json.keys() and len(json['@graph']) >= 1 and prop in json['@graph'][0].keys():
        if isinstance(json['@graph'][0][prop], list):
            for element in json['@graph'][0][prop]:
                result.append(element['@id'])    
        elif '@value' in json['@graph'][0][prop].keys():
            result.append(json['@graph'][0][prop]['@value'])
        elif '@id' in json['@graph'][0][prop].keys():
            result.append(json['@graph'][0][prop]['@id'])
    return result