Ejemplo n.º 1
0
def get_movie_actors(id):
    return sparql("""
        SELECT *
        WHERE {
            ?id worker:played_on movie:""" + id + """.
            ?id worker:name ?name.
        }
    """)
Ejemplo n.º 2
0
def get_movie_genres(id):
    return sparql("""
        SELECT *
        WHERE {
            movie:""" + id + """ movie:genre ?id.
            ?id genre:name ?name.
        }
    """)
Ejemplo n.º 3
0
def get_worked_with(id):
    return sparql("""
            SELECT *
            WHERE {
                worker:""" + id + """ movie:workedWith ?id.
                ?id worker:name ?name.
            }
            LIMIT 6
        """)
Ejemplo n.º 4
0
def get_all_directors():
    return sparql("""
            SELECT ?id ?name (COUNT(?movie) AS ?movies)
            WHERE {
                ?id worker:directed ?movie.
                ?id worker:name ?name.
            }
            GROUP BY ?id ?name
            ORDER BY DESC (?movies)
        LIMIT 500""")
Ejemplo n.º 5
0
def search_movies(term):
    return sparql("""
        SELECT ?id ?title ?year ?score
        WHERE {
            ?id movie:title ?title.
            ?id movie:year ?year.
            ?id movie:score ?score.
            FILTER (CONTAINS(LCASE(?title), LCASE("TERM")))
        }
    """.replace("TERM", term))
Ejemplo n.º 6
0
def get_worker_name(id):
    worker = sparql("""
        SELECT ?name
        WHERE {
            worker:""" + id + """ worker:name ?name.
            }
        LIMIT 1
    """)

    return worker[0]['name'] if worker and 'name' in worker[0] else None
Ejemplo n.º 7
0
def get_director_movies(id):
    return sparql("""
        SELECT ?movie ?title ?year ?score
        WHERE {
            worker:""" + id + """ worker:directed ?movie .
            ?movie movie:title ?title.
            ?movie movie:year ?year.
            ?movie movie:score ?score.
        }
    """)
Ejemplo n.º 8
0
def get_genres():
    return sparql("""
        SELECT ?id ?name
        WHERE { 
            ?id genre:name ?name.
            ?movie movie:genre ?id.
        }
        GROUP BY ?id ?name
        ORDER BY DESC(COUNT(?movie))
    """)
Ejemplo n.º 9
0
def search_actors(term):
    return sparql("""
        SELECT ?id ?name (COUNT(?movie) AS ?movies)
        WHERE {
            ?id worker:played_on ?movie.
            ?id worker:name ?name.
            FILTER (CONTAINS(LCASE(?name), LCASE("TERM")))
        }
        GROUP BY ?id ?name
        ORDER BY DESC (?movies)
    """.replace("TERM", term))
Ejemplo n.º 10
0
def get_all_movies():
    return sparql("""
        SELECT *
        WHERE { 
            ?id movie:title ?title.
            ?id movie:year ?year.
            ?id movie:score ?score.
        }
        ORDER BY DESC(?year) DESC(?score)
        LIMIT 40
    """)
Ejemplo n.º 11
0
def get_movie_details(id):
    result = sparql("""
        SELECT *
        WHERE {
            movie:""" + id + """ movie:title ?title.
            movie:""" + id + """ movie:year ?year.
            movie:""" + id + """ movie:score ?score.
            ?director_id worker:directed movie:""" + id + """.
            ?director_id worker:name ?director.
        }
    """)
    return result[0] if result else None
Ejemplo n.º 12
0
def get_new_movies():
    return sparql("""
        SELECT *
        WHERE { 
            ?id movie:title ?title.
            ?id movie:year ?year.
            ?id movie:score ?score.
            ?id movie:isNew true.
        }
        ORDER BY DESC(?year) DESC(?score)
        LIMIT 6
    """)
Ejemplo n.º 13
0
def movies_by_genre(genre):
    return sparql("""
        SELECT *
        WHERE { 
            ?id movie:title ?movie.
            OPTIONAL{
                ?id movie:year ?year.
                ?id movie:score ?score.
                ?id movie:genre genre:toSearch
            }
        }
        ORDER BY DESC(?year) DESC(?score)
        LIMIT 500
    """.replace("toSearch", genre))
Ejemplo n.º 14
0
def movie(request, id):
    sparql("""
        DELETE {
            movie:""" + id + """ movie:views ?current
        } INSERT{
            movie:""" + id + """ movie:views ?updated
        } WHERE {
            OPTIONAL { movie:""" + id + """ movie:views ?current. }
            BIND ((IF(BOUND(?current), ?current + 1, 1)) AS ?updated)
        }
        """,
           update=True)
    return render(
        request, "movie.html", {
            'id': id,
            'genres': get_genres(),
            'movie': get_movie_details(id),
            'actors': get_movie_actors(id),
            'movie_genres': get_movie_genres(id),
            'awards': get_movie_awards(id),
            'nomeations': get_movie_nomeations(id),
            'companies': get_movie_companies(id)
        })
Ejemplo n.º 15
0
def get_trending_movies():
    return sparql("""
            SELECT *
            WHERE { 
                ?id movie:title ?title.
                ?id movie:year ?year.
                ?id movie:isTrending true.
                OPTIONAL{
                    ?id movie:score ?score.
                }
            }
            ORDER BY DESC(?views) DESC(?year)
            LIMIT 6
        """)
Ejemplo n.º 16
0
def exec_inferences(request, id):
    if id == '00':
        sparql("""
                DELETE {
                    ?old movie:isNew true
                }
                INSERT {
                    ?next movie:isNew true
                }
                WHERE { 
                    {
                        ?old movie:isNew true
                    } UNION { 
                        SELECT ?next
                        WHERE {
                            ?next movie:year ?year.
                            ?next movie:score ?score.
                        }
                        ORDER BY DESC(?year) DESC(?score)
                        LIMIT 6
                    }
                }
            """,
               update=True)
    elif id == '01':
        sparql("""
                INSERT {
                    ?next movie:isTrending true
                }
                WHERE { 
                    {
                        ?old movie:isTrending true
                    } UNION { 
                        SELECT ?next
                        WHERE {
                            ?next movie:year ?year.
                            ?next movie:views ?views.
                        }
                        ORDER BY DESC(?views) DESC(?year)
                        LIMIT 6
                    }
                }
            """,
               update=True)
    elif id == '02':
        sparql("""
                DELETE {
                    ?old_a worker:workedWith ?old_b
                } INSERT {
                    ?worker_a worker:workedWith ?worker_b
                } WHERE { 
                    {
                        ?old_a worker:workedWith ?old_b
                    } UNION { 
                        SELECT *
                        WHERE {
                            ?worker_a worker:played_on ?movie.
                            ?worker_b worker:played_on ?movie.
                            FILTER (?worker_a != ?worker_b).
                        }
                    }
                }
            """,
               update=True)
    return 'OK'