"source": "Instalar\n========\nS\u00f3lo hace falta instalar pyld: https://github.com/digitalbazaar/pyld\n\n```bash\npip install pyld \n```\n\nTambi\u00e9n puedes instalar rdflib para convertir el fichero de xml-rdf a nt.\n\nModificar el frame\n==================\nLo que metas dentro del frame se usa para dos cosas:\n * La parte del contexto se usa para compactizar (reducir nombres, son los prefijos)\n * El total se usa para dar estructura al json final\n \nPor tanto, aqu\u00ed puedes decirle qu\u00e9 espacios de nombres y qu\u00e9 campos usar.\nComo ver\u00e1s, adem\u00e1s de hacer framing hago compact.\n\u00bfPor qu\u00e9?, pues porque el framing deja una lista de objetos colgando de \"@graph\", y si esa lista tiene un s\u00f3lo elemento podemos pasar esos atributos a la \"ra\u00edz\" para hacer m\u00e1s legible el json.\n\nEjemplo\n-------\n```json\n{ ...\n \"@graph\": [ {\"@id\": \"test\", \"name\": \"testing\"}]\n}\n```\n\nSe convierte en:\n\n```json\n{ ...\n \"@id\": \"test\",\n \"name\": \"testing\"\n\n}\n```\n\n\nSin l\u00edos\n========\n\nPuedes usar el json-ld playground para estas cosas: [Enlace](http://json-ld.org/playground/index.html#startTab=tab-framed&json-ld=%7B%22%40context%22%3A%7B%22foaf%22%3A%22http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%22%2C%22owl%22%3A%22http%3A%2F%2Fwww.w3.org%2F2002%2F07%2Fowl%23%22%2C%22rdfs%22%3A%22http%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%22%2C%22image%22%3A%7B%22%40id%22%3A%22http%3A%2F%2Fschema.org%2Fimage%22%2C%22%40type%22%3A%22%40id%22%7D%2C%22tags%22%3A%22http%3A%2F%2Fwww.holygoat.co.uk%2Fowl%2Fredwood%2F0.1%2Ftags%2F%22%2C%22ewe%22%3A%22http%3A%2F%2Fgsi.dit.upm.es%2Fontologies%2Fewe%2Fns%2F%22%2C%22rdf%22%3A%22http%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%22%2C%22xsd%22%3A%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%22%2C%22dcterms%22%3A%22http%3A%2F%2Fpurl.org%2Fdc%2Fterms%2F%22%2C%22homepage%22%3A%7B%22%40id%22%3A%22http%3A%2F%2Fschema.org%2Furl%22%2C%22%40type%22%3A%22%40id%22%7D%2C%22spinrdf%22%3A%22http%3A%2F%2Fspinrdf.org%2Fsp%23%22%7D%2C%22%40graph%22%3A%5B%7B%22%40id%22%3A%22_%3Ab0%22%2C%22spinrdf%3AvarName%22%3A%22message%22%7D%2C%7B%22%40id%22%3A%22_%3Ab1%22%2C%22spinrdf%3AvarName%22%3A%22action%22%7D%2C%7B%22spinrdf%3Atemplates%22%3A%7B%22%40list%22%3A%5B%7B%22spinrdf%3Apredicate%22%3A%7B%22%40id%22%3A%22rdf%3Atype%22%7D%2C%22spinrdf%3Aobject%22%3A%7B%22%40id%22%3A%22http%3A%2F%2Fgsi.dit.upm.es%2Fontologies%2Fewe%23Action%22%7D%2C%22%40id%22%3A%22_%3Ab11%22%2C%22spinrdf%3Asubject%22%3A%7B%22%40id%22%3A%22_%3Ab38%22%2C%22spinrdf%3AvarName%22%3A%22action%22%7D%7D%2C%7B%22spinrdf%3Apredicate%22%3A%7B%22%40id%22%3A%22dcterms%3Atitle%22%7D%2C%22spinrdf%3Aobject%22%3A%22New%20chat%20message%22%2C%22%40id%22%3A%22_%3Ab12%22%2C%22spinrdf%3Asubject%22%3A%7B%22%40id%22%3A%22_%3Ab23%22%2C%22spinrdf%3AvarName%22%3A%22action%22%7D%7D%2C%7B%22spinrdf%3Apredicate%22%3A%7B%22%40id%22%3A%22http%3A%2F%2Fgsi.dit.upm.es%2Fontologies%2Fewe%23hasParameter%22%7D%2C%22spinrdf%3Aobject%22%3A%7B%22%40id%22%3A%22_%3Ab37%22%2C%22spinrdf%3AvarName%22%3A%22iParam%22%7D%2C%22%40id%22%3A%22_%3Ab13%22%2C%22spinrdf%3Asubject%22%3A%7B%22%40id%22%3A%22_%3Ab32%22%2C%22spinrdf%3AvarName%22%3A%22action%22%7D%7D%2C%7B%22spinrdf%3Apredicate%22%3A%7B%22%40id%22%3A%22dcterms%3Atitle%22%7D%2C%22spinrdf%3Aobject%22%3A%22message%22%2C%22%40id%22%3A%22_%3Ab7%22%2C%22spinrdf%3Asubject%22%3A%7B%22%40id%22%3A%22_%3Ab8%22%2C%22spinrdf%3AvarName%22%3A%22iParam%22%7D%7D%2C%7B%22spinrdf%3Apredicate%22%3A%7B%22%40id%22%3A%22dcterms%3Avalue%22%7D%2C%22spinrdf%3Aobject%22%3A%7B%22%40id%22%3A%22_%3Ab0%22%2C%22spinrdf%3AvarName%22%3A%22message%22%7D%2C%22%40id%22%3A%22_%3Ab2%22%2C%22spinrdf%3Asubject%22%3A%7B%22%40id%22%3A%22_%3Ab3%22%2C%22spinrdf%3AvarName%22%3A%22iParam%22%7D%7D%2C%7B%22spinrdf%3Apredicate%22%3A%7B%22%40id%22%3A%22http%3A%2F%2Fgsi.dit.upm.es%2Fontologies%2Fewe%23providesAction%22%7D%2C%22spinrdf%3Aobject%22%3A%7B%22%40id%22%3A%22_%3Ab5%22%2C%22spinrdf%3AvarName%22%3A%22action%22%7D%2C%22%40id%22%3A%22_%3Ab4%22%2C%22spinrdf%3Asubject%22%3A%7B%22%40id%22%3A%22https%3
},
{
"cell_type": "code",
"collapsed": false,
2014-04-02 19:38:31 +00:00
"input": "from rdflib import Graph\ng = Graph()",
2014-04-02 19:27:49 +00:00
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
2014-04-02 19:38:31 +00:00
{
"cell_type": "code",
"collapsed": true,
"input": " # rdf = open('example.rdf', 'r')\n from StringIO import StringIO\n rdf = StringIO('''<?xml version=\"1.0\" encoding=\"utf-8\"?>\n \n <rdf:RDF \n xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" \n xmlns:owl=\"http://www.w3.org/2002/07/owl#\" \n xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" \n xmlns:ewe=\"http://gsi.dit.upm.es/ontologies/ewe/ns/\" \n xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\" \n xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" \n xmlns:dcterms=\"http://purl.org/dc/terms/\" \n xmlns:tags=\"http://www.holygoat.co.uk/owl/redwood/0.1/tags/\" \n xmlns=\"http://gsi.dit.upm.es/ontologies/ewe/ns/\">\n \n <!-- Channel Instance Description -->\n <ewe:Channel rdf:about=\"https://ifttt.com/gmail\">\n <dcterms:title>Gmail</dcterms:title>\n <dcterms:description>Googles approach to email, Gmail, is built on the idea that email can be moreintuitive, efficient, and useful. And maybe even fun.</dcterms:description>\n <foaf:url>http://gmail.com</foaf:url>\n <foaf:logo>https://ifttt.com/images/channels/gmail_lrg.png</foaf:logo>\n <!-- Event and action references -->\n <ewe:generatesEvent rdf:resource=\"https://ifttt.com/channels/gmail/triggers/87\" />\n <ewe:generatesEvent rdf:resource=\"https://ifttt.com/channels/gmail/triggers/85\" />\n <ewe:generatesEvent rdf:resource=\"https://ifttt.com/channels/gmail/triggers/186\" />\n <ewe:generatesEvent rdf:resource=\"https://ifttt.com/channels/gmail/triggers/86\" />\n <ewe:generatesEvent rdf:resource=\"https://ifttt.com/channels/gmail/triggers/367\" />\n <ewe:generatesEvent rdf:resource=\"https://ifttt.com/channels/gmail/triggers/185\" /> \n <ewe:providesAction rdf:resource=\"https://ifttt.com/channels/gmail/actions/34\" />\n </ewe:Channel>\n \n <!-- Event Instances -->\n <ewe:Event rdf:about=\"https://ifttt.com/channels/gmail/triggers/87\">\n <dcterms:title>New email from search</dcterms:title> \n <dcterms:description>This Trigger fires every time a new email arrives in your inbox that matchesthe search query you specify.</dcterms:description> \n <ewe:hasOutputParameter>\n <ewe:outputParameter>\n <dcterms:title>FromAddress</dcterms:title> \n <dcterms:description>Email address of sender.</dcterms:description> \n <ewe:example>somebody@gmail.com</ewe:example> \n </ewe:outputParameter>\n </ewe:hasOutputParameter>\n <ewe:hasOutputParameter>\n <ewe:outputParameter>\n <dcterms:title>Subject</dcterms:title> \n <dcterms:description>Email subject line.</dcterms:description> \n <ewe:example>Hello there</ewe:example> \n </ewe:outputParameter>\n </ewe:hasOutputParameter>\n <ewe:hasOutputParameter>\n <ewe:outputParameter>\n <dcterms:title>BodyPlain</dcterms:title> \n <dcterms:description>Plain text email body.</dcterms:description> \n <ewe:example>Been having a good day so far...</ewe:example> \n </ewe:outputParameter>\n </ewe:hasOutputParameter>\n <ewe:hasOutputParameter>\n <ewe:outputParameter>\n <dcterms:title>FirstAttachmentPrivateURL</dcterms:title> \n <dcterms:description>A URL to the first file attachment (if any) that only you can see.</dcterms:description> \n <ewe:example>https://locker.ifttt.com/f/29b08556-ac73-11e2-a707-22000a9730cf</ewe:example> \n </ewe:outputParameter>\n </ewe:hasOutputParameter>\n <ewe:hasOutputParameter>\n <ewe:outputParameter>\n <dcterms:title>FirstAttachmentPublicURL</dcterms:title> \n