from rdflib import Graph


def is_valid(resource, file):
    """Check if file is a valid RDF document."""

    try:
        graph = Graph()
        graph.parse(file.name)

        # even an empty RDF document contains two statements
        if len(graph) > 2:
            return True
        else:
            resource["error"] = "RDF document does not contain any statements."
            return False
    except Exception as e:
        resource["error"] = str(e)
        return False