Skip to content

Commit

Permalink
person page microformat
Browse files Browse the repository at this point in the history
  • Loading branch information
situx committed Jan 15, 2024
1 parent 9c13f85 commit 7d64703
Showing 1 changed file with 88 additions and 12 deletions.
100 changes: 88 additions & 12 deletions src/sparqlunicorn_ontdoc/export/pages/personpage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,74 @@
from doc.docconfig import DocConfig
from doc.docutils import DocUtils
import json
from ...doc.docutils import DocUtils
from ...sparqlutils import SPARQLUtils


class PersonPage:

vcardTohCard={
"http://xmlns.com/foaf/0.1/birthday":"dt-bday",
"http://xmlns.com/foaf/0.1/familyName":"p-family-name",
"http://xmlns.com/foaf/0.1/family_name": "p-family-name",
"http://xmlns.com/foaf/0.1/firstName": "p-given-name",
"http://xmlns.com/foaf/0.1/lastName": "p-family-name",
"http://xmlns.com/foaf/0.1/fullName":"FN",
"http://xmlns.com/foaf/0.1/givenname": "p-given-name",
"http://xmlns.com/foaf/0.1/givenName":"p-given-name",
"http://xmlns.com/foaf/0.1/homePage":"u-url",
"http://xmlns.com/foaf/0.1/gender": "p-sex",
"http://xmlns.com/foaf/0.1/img":"u-photo",
"http://xmlns.com/foaf/0.1/logo":"u-logo",
"http://xmlns.com/foaf/0.1/mbox":"u-email",
"http://xmlns.com/foaf/0.1/name":"N",
"http://xmlns.com/foaf/0.1/nick":"p-nickname",
"http://xmlns.com/foaf/0.1/phone":"p-tel",
"http://xmlns.com/foaf/0.1/surname":"p-family-name",
"http://xmlns.com/foaf/0.1/title":"p-job-title",
"http://www.w3.org/2000/10/swap/pim/contact#address": "p-street-address",
"http://www.w3.org/2000/10/swap/pim/contact#birthday": "dt-bday",
"http://www.w3.org/2000/10/swap/pim/contact#emailAddress": "u-email",
"http://www.w3.org/2000/10/swap/pim/contact#fax":"p-fax",
"http://www.w3.org/2000/10/swap/pim/contact#firstName": "p-given-name",
"http://www.w3.org/2000/10/swap/pim/contact#homepage": "u-url",
"http://www.w3.org/2000/10/swap/pim/contact#knownAs": "p-nickname",
"http://www.w3.org/2000/10/swap/pim/contact#lastName": "p-family-name",
"http://www.w3.org/2000/10/swap/pim/contact#personalTitle": "p-job-title",
"http://www.w3.org/2000/10/swap/pim/contact#phone":"p-tel",
"http://www.w3.org/2006/vcard/ns#additional-name":"p-additional-name",
"http://www.w3.org/2006/vcard/ns#anniversary":"dt-anniversary",
"http://www.w3.org/2006/vcard/ns#bday":"dt-bday",
"http://www.w3.org/2006/vcard/ns#email":"u-email",
"http://www.w3.org/2006/vcard/ns#family-name":"p-family-name",
"http://www.w3.org/2006/vcard/ns#fax":"p-fax",
"http://www.w3.org/2006/vcard/ns#geo":"p-geo",
"http://www.w3.org/2006/vcard/ns#given-name":"p-given-name",
"http://www.w3.org/2006/vcard/ns#hasAddress":"p-street-address",
"http://www.w3.org/2006/vcard/ns#hasEmail":"u-email",
"http://www.w3.org/2006/vcard/ns#hasGeo":"p-geo",
"http://www.w3.org/2006/vcard/ns#hasGender":"p-sex",
"http://www.w3.org/2006/vcard/ns#hasLogo":"u-logo",
"http://www.w3.org/2006/vcard/ns#hasName":"N",
"http://www.w3.org/2006/vcard/ns#hasPhoto":"u-photo",
"http://www.w3.org/2006/vcard/ns#hasSound":"u-sound",
"http://www.w3.org/2006/vcard/ns#hasTelephone":"p-tel",
"http://www.w3.org/2006/vcard/ns#hasURL":"u-url",
"http://www.w3.org/2006/vcard/ns#homeTel":"p-tel",
"http://www.w3.org/2006/vcard/ns#honorific-prefix":"p-honorific-prefix",
"http://www.w3.org/2006/vcard/ns#honorific-suffix":"p-honorific-suffix",
"http://www.w3.org/2006/vcard/ns#latitude":"p-latitude",
"http://www.w3.org/2006/vcard/ns#longitude":"p-longitude",
"http://www.w3.org/2006/vcard/ns#logo":"u-logo",
"http://www.w3.org/2006/vcard/ns#mobileEmail":"u-email",
"http://www.w3.org/2006/vcard/ns#mobileTel":"p-tel",
"http://www.w3.org/2006/vcard/ns#role":"p-role",
"http://www.w3.org/2006/vcard/ns#street-address": "p-street-address",
"http://www.w3.org/2006/vcard/ns#sound":"u-sound",
"http://www.w3.org/2006/vcard/ns#tel":"p-tel",
"http://www.w3.org/2006/vcard/ns#title":"p-job-title",
"http://www.w3.org/2006/vcard/ns#url":"u-url",
"http://www.w3.org/2006/vcard/ns#workEmail":"u-email",
"http://www.w3.org/2006/vcard/ns#workTel":"p-tel"
}

vcardprops={
"http://xmlns.com/foaf/0.1/birthday":"BDAY",
"http://xmlns.com/foaf/0.1/familyName":"N",
Expand Down Expand Up @@ -53,7 +118,7 @@ class PersonPage:
"http://www.w3.org/2006/vcard/ns#hasURL":"URL",
"http://www.w3.org/2006/vcard/ns#homeTel":"TEL",
"http://www.w3.org/2006/vcard/ns#honorific-prefix":"TITLE",
"http://www.w3.org/2006/vcard/ns#honorific-suffix"
"http://www.w3.org/2006/vcard/ns#honorific-suffix":"",
"http://www.w3.org/2006/vcard/ns#latitude":"LATITUDE",
"http://www.w3.org/2006/vcard/ns#longitude":"LONGITUDE",
"http://www.w3.org/2006/vcard/ns#logo":"LOGO",
Expand All @@ -69,43 +134,54 @@ class PersonPage:
"http://www.w3.org/2006/vcard/ns#workTel":"TEL"
}

def createNameProperty(self,vcard):
print("create the name from differently mapped N values")


def extractPersonMetadata(self,subject,graph):
thevcard={}
for pprop in graph.predicate_objects(subject, True):
if str(pprop[0]) in self.vcardprops:
thevcard[self.vcardprops[str(pprop[0])]]={"value":str(pprop[1]),"prop":str(pprop[0])}
if self.vcardprops[str(pprop[0])] in thevcard:
thevcard[self.vcardprops[str(pprop[0])]]["value"]+=" "+str(pprop[1])
else:
thevcard[self.vcardprops[str(pprop[0])]]={"value":str(pprop[1]),"prop":str(pprop[0])}
return thevcard

def vcardToHTML(self,vcard):
result="<table id=\"person\" class=\"vcard\" border=\"1\"><thead><tr><th>Property</th><th>Value</th></tr></thead><tbody>"
result="<table id=\"person\" class=\"h-card\" border=\"1\"><thead><tr><th>Property</th><th>Value</th></tr></thead><tbody>"
for prop in vcard:
result+="<tr><td><a href=\""+str(vcard[prop]["prop"])+"\">"+str(DocUtils.shortenURI(prop))+"</a></td>"
if "http" in vcard[prop]:
result+="<td><a href=\""+str(vcard[prop]["value"])+"\" class=\""+str(prop)+"\">"+str(DocUtils.shortenURI(vcard[prop]["value"]))+"</a></td></tr>"
else:
result += "<td class=\""+str(prop)+"\">" + str(vcard[prop]["value"]) + "</td></tr>"
result+="</tbody></table><script>vcard="+json.dumps(vcard)+"; $('#person').DataTable();</script><button id=\"vcard\" onclick=\"saveTextAsFile(JSON.stringify(vcard),'json')\">Download VCard</button>"
if vcard[prop]["prop"] in self.vcardTohCard:
result += "<td class=\"" + str(self.vcardTohCard[vcard[prop]["prop"]]) + "\">" + str(vcard[prop]["value"]) + "</td></tr>"
else:
result += "<td class=\""+str(prop)+"\">" + str(vcard[prop]["value"]) + "</td></tr>"
result+="</tbody></table><script>$('#person').DataTable();</script><button id=\"vcard\">Download VCard</button>"
return result


@staticmethod
def collectionConstraint():
return DocConfig.collectionclasses
return SPARQLUtils.collectionclasses

@staticmethod
def pageWidgetConstraint():
return ["http://xmlns.com/foaf/0.1/Person","http://www.w3.org/2006/vcard/ns#Individual","http://schema.org/Person","http://dbpedia.org/ontology/Person","http://www.wikidata.org/entity/Q5"]

def generatePageWidget(self, graph, subject, templates, f=None, pageWidget=False):
print("PageWidget")
vcard=self.extractPersonMetadata(subject,graph)
if pageWidget and f!=None:
f.write(self.vcardToHTML(vcard))
return vcard



def generateCollectionWidget(self, graph, templates, subject, f=None):
print("CollectionWidget")
vcards=[]
for person in graph.predicate_objects(subject):
if str(person[0]) in DocConfig.collectionrelationproperties:
if str(person[0]) in SPARQLUtils.collectionrelationproperties:
vcards.append(self.generatePageWidget(graph,person[1],templates,f,True))
return vcards

0 comments on commit 7d64703

Please sign in to comment.