Lab: Semantic Lifting - XML: Difference between revisions

From info216
No edit summary
No edit summary
Line 21: Line 21:


==Code to Get Started (You could also use your own approach if you want to) ==
==Code to Get Started (You could also use your own approach if you want to) ==
<syntaxhighlight>
from rdflib import Graph, Literal, Namespace, URIRef
from rdflib.namespace import RDF, XSD
import xml.etree.ElementTree as ET
import requests
import re


g = Graph()
ex = Namespace("http://example.org/")
prov = Namespace("http://www.w3.org/ns/prov#")
g.bind("ex", ex)
g.bind("ex", prov)
# url of rss feed
url = 'http://feeds.bbci.co.uk/news/rss.xml'
# creating HTTP response object from given url
resp = requests.get(url)
# saving the xml file
with open('test.xml', 'wb') as f:
    f.write(resp.content)
</syntaxhighlight>





Revision as of 23:08, 18 March 2020

Lab 10: Semantic Lifting - XML

Link to Discord server

https://discord.gg/t5dgPrK

Topics

Today's topic involves lifting data in XML format into RDF. XML stands for Extensible Markup Language and is used to... The goal is for you to learn an example of how we can convert unsemantic data into RDF.


Relevant Libraries/Functions

Tasks

If You have more Time

Code to Get Started (You could also use your own approach if you want to)

from rdflib import Graph, Literal, Namespace, URIRef
from rdflib.namespace import RDF, XSD
import xml.etree.ElementTree as ET
import requests
import re

g = Graph()
ex = Namespace("http://example.org/")
prov = Namespace("http://www.w3.org/ns/prov#")
g.bind("ex", ex)
g.bind("ex", prov)


# url of rss feed
url = 'http://feeds.bbci.co.uk/news/rss.xml'

# creating HTTP response object from given url
resp = requests.get(url)

# saving the xml file
with open('test.xml', 'wb') as f:
    f.write(resp.content)



Useful Reading

XML-parsing-python by geeksforgeeks.org