Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import etree, objectify
- NSMAP = {
- "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
- "rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
- "dcterms" : "http://purl.org/dc/elements/1.1/",
- "foaf" : "http://xmlns.com/foaf/0.1/",
- "owl" : "http://www.w3.org/2002/07/owl#",
- "sioc" : "http://rdfs.org/sioc/ns#",
- "pt" : "http://www.pearltrees.com/rdf/0.1/#"
- }
- # Import this code as follows:
- #with open("variables.py") as fi:
- # exec(fi.read())
- #
- #
- # To understand this code see:
- # #https://lxml.de/objectify.html
- #
- # Random URL for now readson:
- # https://medium.com/@snehalgawas/back-to-basics-jupyter-notebooks-dfcdc19c54bc
- #
- #<?xml version="1.0" encoding="utf-8"?>
- #
- #<!--
- #*******************************************************************************************#*****************
- #* This is a Pearltrees export of your account.
- #*
- #* You are the full owner of the data you have stored in Pearltrees.
- #* This RDF file is your Pearltrees account turned into a W3C-compliant format.
- #*
- #* To developers:
- #* - The author is identified by a FOAF profile with a SIOC account.
- #* - The most important classes are "pt:Tree" and "pt:PagePearl".
- #* - "pt:Pearl" refers to its parent tree with the "pt:parentTree" property.
- #* - "pt:leftPos" and "pt:rightPos" are nested set values (see #"http://en.wikipedia.org/wiki/Nested_set_model")
- #* - Most properties and classes are not stable.
- #* More to come:
- #* - Full documentation.
- #* - Publishing schema and OWL descriptions.
- #* - Dereferenceable URIs.
- #* Interested in more RDF data? Any suggestion? Send us an email at #<participation@pearltrees.net>!
- #*******************************************************************************************#*****************
- #-->
- #
- #
- #<?xml version="1.0" encoding="UTF-8"?>
- #
- #<!-- 0.1 : First rough version -->
- #
- #<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- # xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- # xmlns:foaf="http://xmlns.com/foaf/0.1/"
- # xmlns:dcterms="http://purl.org/dc/elements/1.1/"
- # xmlns:pt="http://www.pearltrees.com/rdf/0.1/#">
- #
- #<!-- Main Classes -->
- root=objectify.Element("{http://www.w3.org/1999/02/22-rdf-syntax-ns#}rdf",nsmap=NSMAP)
- print("type of root:" + str(type(root)))
- #<foaf:Person rdf:about="https://www.pearltrees.com/somebody#foaf">
- # <foaf:nick>somebody</foaf:nick>
- # <foaf:mbox_sha1sum>somesha1sum/foaf:mbox_sha1sum>
- # <foaf:mbox>somebody@hotmail.com</foaf:mbox>
- # <sioc:UserAccount rdf:resource="https://www.pearltrees.com/somebody#sioc" />
- #</foaf:Person>
- person=objectify.SubElement(root,"{http://xmlns.com/foaf/0.1/}Person")
- print("type of person:" + str(type(person)))
- #<sioc:UserAccount rdf:about="https://www.pearltrees.com/somebody#sioc">
- # <pt:rootTree rdf:resource="https://www.pearltrees.com/somebody" />
- # <sioc:account_of rdf:resource="https://www.pearltrees.com/somebody#foaf" />
- # <sioc:ip_address>someIPaddr</sioc:ip_address>
- #</sioc:UserAccount>
- account=objectify.SubElement(root,"{http://rdfs.org/sioc/ns#}UserAccount")
- print("type of account:" + str(type(account)))
- # - In the orginal pearltrees a tree once was analoges to a mind map for a given
- # topic. (e.g. ...)
- # - In PT2.0 and on the mindmap concept was replaced by a grid like strucures
- # and each node of the tree was replaced by a buch of cards.
- # - In either case the tree is the principle web page for each topic containing a number
- # of sub items. One major difference is that later version of pearltree lose much of the
- # tree struture.
- #<pt:Tree rdf:about="url_for_some_tree">
- # <dcterms:title><![CDATA[tree_title]]></dcterms:title>
- # <dcterms:creator rdf:resource="https://www.pearltrees.com/somebody#sioc" />
- # <pt:treeId>tree_id</pt:treeId>
- # <pt:assoId>tree_id</pt:assoId>
- # <pt:lastUpdate>2012-05-23T20:00:32</pt:lastUpdate>
- # <pt:privacy>0</pt:privacy>
- #</pt:Tree>
- curr_tree=objectify.SubElement(root,"{http://www.pearltrees.com/rdf/0.1/#}Tree",nsmap=NSMAP)
- curr_title=objectify.SubElement(curr_tree,"{http://purl.org/dc/elements/1.1/}title",nsmap=NSMAP)
- curr_title._setText('<![CDATA["some title"]]>')
- curr_creator=objectify.SubElement(curr_tree,"{http://purl.org/dc/elements/1.1/}creator",nsmap=NSMAP)
- curr_creator._setText("creator")
- curr_tree_Id=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}treeId",nsmap=NSMAP)
- curr_tree_Id._setText("tree_id")
- curr_assoId=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}assoId",nsmap=NSMAP)
- curr_assoId._setText("tree_id")
- curr_lastUpdate=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}lastUpdate",nsmap=NSMAP)
- curr_lastUpdate._setText("last_id")
- curr_privacy=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}privacy",nsmap=NSMAP)
- curr_privacy._setText("privacy")
- #print(etree.tostring(curr_tree, pretty_print=True))
- print(etree.tostring(curr_tree, pretty_print=True, xml_declaration=True,encoding='UTF8').decode("unicode_escape"))
- print("type of curr_tree:" + str(type(curr_tree)))
- # - When pearltrees used mindmaps the rootPearl was the root of the tree.
- # - In later version this idea was kept even if the tree structure was abandoned.
- # - As a consequence all items of type PearlTree have a root node.
- # - The root node always has PosOrder=1, which is equivalent to (for the root node):
- # leftPos=posORder
- # rightPos=[The number of pearls multipled by 2]
- # where leftPos and rightPos define the postion of the root pearl in the nexted set model
- # and all pearls are nested within the root node but no deeper.
- #
- # this creats an equivalence between the new linear model (using posOrder) and the previous
- # tree model which used leftPos and rightPos to encode a nested set model.
- #
- #
- #
- #<pt:RootPearl rdf:about="https://url_for_some_tree#rootPearl">
- # <dcterms:title><![CDATA[tree_title]]></dcterms:title>
- # <pt:parentTree rdf:resource="https://url_for_some_tree" />
- # <pt:inTreeSinceDate>2012-05-23T20:00:32</pt:inTreeSinceDate>
- # <pt:posOrder>1</pt:posOrder>
- #</pt:RootPearl>
- curr_pearl=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}RootPearl")
- curr_title=objectify.SubElement(curr_pearl,"{http://purl.org/dc/elements/1.1/}title",nsmap=NSMAP)
- curr_title._setText('<![CDATA["some title"]]>')
- #print(etree.tostring(curr_tree, pretty_print=True))
- curr_parentTree=objectify.SubElement(curr_pearl,"{http://www.pearltrees.com/rdf/0.1/#}parentTree",nsmap=NSMAP)
- curr_parentTree._setText(curr_tree_Id.text)
- curr_inTreeSinceDate=objectify.SubElement(curr_pearl,"{http://www.pearltrees.com/rdf/0.1/#}inTreeSinceDate",nsmap=NSMAP)
- curr_inTreeSinceDate._setText("some_date")
- curr_posOrder=objectify.SubElement(curr_pearl,"{http://www.pearltrees.com/rdf/0.1/#}inTreeSinceDate",nsmap=NSMAP)
- curr_posOrder._setText("some_date")
- print(etree.tostring(curr_pearl, pretty_print=True, xml_declaration=True,encoding='UTF8').decode("unicode_escape"))
- print("type of curr_pearl:" + str(type(curr_pearl)))
- # Recall that a Tree is like the principle page about a topic and it can contain sevearl items. One item it
- # can contain is a link to an external web page. Such items are called "PagePearl". These items store additional
- # information about the external URL beyond the url, such a comments, text, and images.
- #
- #<pt:PagePearl rdf:about="https://www.pearltrees.com/t/hacktivism/irl-hacktivists-groups/id2492374#item18082864">
- # <dcterms:title><![CDATA[/tmp/lab | Creative use of technology]]></dcterms:title>
- # <dcterms:identifier>http://www.tmplab.org/</dcterms:identifier>
- # <pt:parentTree rdf:resource="https://www.pearltrees.com/t/hacktivism/irl-hacktivists-groups/id2492374" />
- # <pt:inTreeSinceDate>2011-02-07T02:42:18</pt:inTreeSinceDate>
- # <pt:posOrder>2</pt:posOrder>
- #</pt:PagePearl>
- curr_PagePearl=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1#}PagePearl",nsmap=NSMAP)
- curr_title=objectify.SubElement(curr_PagePearl,"{http://purl.org/dc/elements/1.1/}title",nsmap=NSMAP)
- curr_title._setText('<![CDATA["some title"]]>')
- #print(etree.tostring(curr_tree, pretty_print=True))
- curr_identifier=objectify.SubElement(curr_PagePearl,"{http://www.pearltrees.com/rdf/0.1/#}identifier",nsmap=NSMAP)
- curr_identifier._setText("some_wepage_url")
- curr_inTreeSinceDate=objectify.SubElement(curr_PagePearl,"{http://www.pearltrees.com/rdf/0.1/#}inTreeSinceDate",nsmap=NSMAP)
- curr_inTreeSinceDate._setText("some_date")
- curr_posOrder=objectify.SubElement(curr_PagePearl,"{http://www.pearltrees.com/rdf/0.1/#}posOrder",nsmap=NSMAP)
- curr_posOrder._setText("some_date")
- print(etree.tostring(curr_PagePearl, pretty_print=True, xml_declaration=True,encoding='UTF8').decode("unicode_escape"))
- print("type of curr_PagePearl:" + str(type(curr_PagePearl)))
- #
- # t
- #
- #
- # <pt:AliasPearl rdf:about="https://www.pearltrees.com/t/hacktivism/id2492215#item18110176&show=item,18110176">
- # <dcterms:title><![CDATA[Anonymous Culture]]></dcterms:title>
- # <rdfs:seeAlso rdf:resource="https://www.pearltrees.com/anon/anonymous-culture/id2421304" />
- # <pt:parentTree rdf:resource="https://www.pearltrees.com/t/hacktivism/id2492215" />
- # <pt:inTreeSinceDate>2011-02-07T14:40:33</pt:inTreeSinceDate>
- # <pt:posOrder>2</pt:posOrder>
- # </pt:AliasPearl>
- curr_AliasPearl=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}AliasPearl",nsmap=NSMAP)
- curr_title=objectify.SubElement(curr_AliasPearl,"{http://purl.org/dc/elements/1.1/}title",nsmap=NSMAP)
- curr_title._setText('<![CDATA["some title"]]>')
- #print(etree.tostring(curr_tree, pretty_print=True))
- curr_parentTree=objectify.SubElement(curr_AliasPearl,"{http://www.pearltrees.com/rdf/0.1/#}parentTree",nsmap=NSMAP)
- curr_parentTree._setText(curr_tree_Id.text)
- curr_inTreeSinceDate=objectify.SubElement(curr_AliasPearl,"{http://www.pearltrees.com/rdf/0.1/#}inTreeSinceDate",nsmap=NSMAP)
- curr_inTreeSinceDate._setText("some_date")
- curr_posOrder=objectify.SubElement(curr_AliasPearl,"{http://www.pearltrees.com/rdf/0.1/#}posOrder",nsmap=NSMAP)
- curr_posOrder._setText("some_posOrder")
- print(etree.tostring(curr_AliasPearl, pretty_print=True, xml_declaration=True,encoding='UTF8').decode("unicode_escape"))
- print("type of curr_AliasPearl:" + str(type(curr_AliasPearl)))
- # <pt:RefPearl rdf:about="https://www.pearltrees.com/t/hacktivism-s-litteracy/id2492416?show=item,18806157">
- # <dcterms:title><![CDATA[EN]]></dcterms:title>
- # <rdfs:seeAlso rdf:resource="https://www.pearltrees.com/t/hacktivism-s-litteracy/en/id2595429" />
- # <pt:parentTree rdf:resource="https://www.pearltrees.com/t/hacktivism-s-litteracy/id2492416" />
- # <pt:inTreeSinceDate>2011-02-28T19:42:18</pt:inTreeSinceDate>
- # <pt:posOrder>2</pt:posOrder>
- # </pt:RefPearl>
- curr_RefPearl=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}RefPearl",nsmap=NSMAP)
- curr_title=objectify.SubElement(curr_RefPearl,"{http://purl.org/dc/elements/1.1/}title",nsmap=NSMAP)
- curr_title._setText('<![CDATA["some title"]]>')
- #print(etree.tostring(curr_tree, pretty_print=True))
- curr_seeAlso=objectify.SubElement(curr_RefPearl,"{http://www.pearltree/rdf/0.1/#}seeAlso",nsmap=NSMAP)
- curr_seeAlso._setText("some_seealso")
- curr_parentTree=objectify.SubElement(curr_RefPearl,"{http://www.pearltrees.com/rdf/0.1/#}parentTree",nsmap=NSMAP)
- curr_parentTree._setText(curr_tree_Id.text)
- curr_inTreeSinceDate=objectify.SubElement(curr_RefPearl,"{http://www.pearltrees.com/rdf/0.1/#}inTreeSinceDate",nsmap=NSMAP)
- curr_inTreeSinceDate._setText("some_date")
- curr_posOrder=objectify.SubElement(curr_RefPearl,"{http://www.pearltrees.com/rdf/0.1/#}posOrder",nsmap=NSMAP)
- curr_posOrder._setText("some_posOrder")
- print(etree.tostring(curr_RefPearl, pretty_print=True, xml_declaration=True,encoding='UTF8').decode("unicode_escape"))
- print("type of curr_RefPearl:" + str(type(curr_RefPearl)))
- # <pt:Note>
- # <dcterms:creator rdf:resource="https://www.pearltrees.com/zarby#sioc" />
- # <dcterms:date>2011-03-01T11:57:52</dcterms:date>
- # <pt:noteText><![CDATA[En effet, les Pearl directs aux articles ne peuvent être changé. Mais merci! C'est une bonne idée!]]></pt:noteText>
- # <pt:parentPearl rdf:resource="https://www.pearltrees.com/t/hacktivism-s-litteracy/pdf-livres/id2595431" />
- # </pt:Note>
- curr_Note=objectify.SubElement(curr_tree,"{http://www.pearltrees.com/rdf/0.1/#}Note",nsmap=NSMAP)
- curr_creator=objectify.SubElement(curr_Note,"{http://purl.org/dc/elements/1.1/}creator",nsmap=NSMAP)
- curr_creator._setText("creator")
- curr_date=objectify.SubElement(curr_Note,"{http://purl.org/dc/elements/1.1/}date",nsmap=NSMAP)
- curr_date._setText("creator")
- curr_noteText=objectify.SubElement(curr_Note,"{http://www.pearltrees.com/rdf/0.1/#}noteText",nsmap=NSMAP)
- curr_noteText._setText("some_note_text")
- print(etree.tostring(curr_Note, pretty_print=True, xml_declaration=True,encoding='UTF8').decode("unicode_escape"))
- print("type of curr_Note:" + str(type(curr_Note)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement