FalaG FalaG - 1 year ago 66
Python Question

Using RDFLib to verify if a file is an RDF graph or not

Is it possible to verify if a file (XML file ) has an RDF/XML structure (verify if it is a correct RDF file) using RDFLib in python or not ?
In case it is possible how should I proceed that and in case it is not, what tools can I use to make the verification ?

Answer Source

For the people facing the same issue this is the solution that I figure it out using RDFLib:

           text_file = open("Output.rdf", "r") #the RDF file that you want to verify
           g = Graph()
           g.parse(text_file, format="xml")
           print "file validate"
           print len(g)

        except Exception as e:
           print "file does not validate"