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 # # # # # # # # # # # # # root=objectify.Element("{http://www.w3.org/1999/02/22-rdf-syntax-ns#}rdf",nsmap=NSMAP) print("type of root:" + str(type(root))) # # somebody # somesha1sum/foaf:mbox_sha1sum> # somebody@hotmail.com # # person=objectify.SubElement(root,"{http://xmlns.com/foaf/0.1/}Person") print("type of person:" + str(type(person))) # # # # someIPaddr # 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. # # # # tree_id # tree_id # 2012-05-23T20:00:32 # 0 # 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('') 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. # # # # # # # 2012-05-23T20:00:32 # 1 # 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('') #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. # # # # http://www.tmplab.org/ # # 2011-02-07T02:42:18 # 2 # 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('') #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 # # # # # # # 2011-02-07T14:40:33 # 2 # 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('') #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))) # # # # # 2011-02-28T19:42:18 # 2 # 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('') #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))) # # # 2011-03-01T11:57:52 # # # 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)))