text:
__author__ = 'Ciro Mattia Gonano <ciromattia@gmail.com>'
__license__ = 'ISC'
__copyright__ = '2014, Ciro Mattia Gonano <ciromattia@gmail.com>'
__docformat__ = 'restructuredtext en'

from rdflib import Namespace, Literal, RDF, RDFS
from hashlib import sha1
from urllib import quote_plus

# init namespaces
DC = Namespace("http://purl.org/dc/elements/1.1/")
DCTERMS = Namespace("http://purl.org/dc/terms/")
FOAF = Namespace("http://xmlns.com/foaf/0.1/")
CRM = Namespace("http://www.cidoc-crm.org/cidoc-crm/")
PRO = Namespace("http://purl.org/spar/pro/")
TIME = Namespace("http://www.w3.org/2006/time#")
FABIO = Namespace("http://purl.org/spar/fabio/")
FENTRY = Namespace("http://www.essepuntato.it/2014/03/fentry/")
FRBR = Namespace("http://purl.org/vocab/frbr/core#")
PROV = Namespace("http://www.w3.org/ns/prov#")
# TODO: add DATACITE to identificators
DATACITE = Namespace("http://purl.org/spar/datacite")
QUDT = Namespace("http://qudt.org/vocab/unit#")
FZERI_FENTRY = Namespace("http://fe.fondazionezeri.unibo.it/catalogo/schedaF/")
FZERI_OAENTRY = Namespace("http://fe.fondazionezeri.unibo.it/catalogo/schedaOA/")
FZERI_NEGATIVE = Namespace("http://fe.fondazionezeri.unibo.it/catalogo/negative/")
FZERI_DIMAGES = Namespace("http://fe.fondazionezeri.unibo.it/foto/")
FZERI_COLLECTION = Namespace("http://fe.fondazionezeri.unibo.it/collection/")

FZERI_DIMENSION = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/dimension/")
FZERI_SERIE = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/serie/")
FZERI_BOX = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/box/")
FZERI_MATERIAL = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/material/")
FZERI_ENTRYTYPE = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/entry_type/")
FZERI_IDENTIFIER = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/identifier/")
FZERI_PHOTOFORMAT = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/photo_format/")
FZERI_PHOTOCOLOR = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/photo_color/")
FZERI_PHOTOTYPE = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/photo_type/")
FZERI_CONDITIONTYPE = Namespace("http://fe.fondazionezeri.unibo.it/thesauri/condition_type/")

unit_fzeri_to_qudt = {
    'mm': QUDT.Millimeter,
    'cm': QUDT.Centimeter,
    'm': QUDT.Meter,
}

class FZeriParserSchedaF:
    def __init__(self, xmlentry, graph):
        self.entry_id = self.oaentry_id = self.negative_id = self.myentry = None
        self.xmlentry = xmlentry
        self.graph = graph
        self.production_counter = 0

    def parse(self):
        try:
            self.entry_id = self.xmlentry.find("PARAGRAFO/SERCD").text
            self.oaentry_id = self.xmlentry.find("PARAGRAFO/SERCDOA").text
        except AttributeError:
            print "Entry has no ID!!!"
            return
        try:
            self.negative_id = quote_plus(self.xmlentry.find("PARAGRAFO/ROFI").text)
        except AttributeError:
            self.negative_id = None

        self.init_graph()

        # Process all paragraphs
        for child in self.xmlentry.findall("PARAGRAFO"):
            if len(child):   # paragraph does contain at least one subelement
                if child[0].tag == "RIPETIZIONE":
                    for repchild in child:
                        # call the appropriate parse_paragraph_* function
                        getattr(self, "parse_paragraph_" +
                                      child.attrib["etichetta"].lower().
                                replace(' ', '_').replace('(', '').replace(')', ''))(repchild, repchild.attrib['prog'])
                else:
                    # call the appropriate parse_paragraph_* function
                    getattr(self, "parse_paragraph_" + child.attrib["etichetta"].lower().
                            replace(' ', '_').replace('(', '').replace(')', ''))(child)

    # Init graph with the entry and various global resources
    def init_graph(self):
        self.myentry = FZERI_FENTRY[self.entry_id]
        self.graph.add((self.myentry, RDF.type, CRM.E31_Document))
        self.graph.add((self.myentry, RDF.type, FENTRY.FEntry))
        self.graph.add((self.myentry, CRM.P1_is_identified_by, Literal(self.entry_id)))
        title = FZERI_FENTRY[self.entry_id + '/title']
        self.graph.add((title, RDF.type, CRM.E35_Title))
        self.graph.add((title, RDF.type, DCTERMS.title))
        self.graph.add((title, RDFS.label, Literal(self.xmlentry.attrib['intestazione'])))
        self.graph.add((self.myentry, CRM.P102_has_title, title))
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        self.graph.add((myphoto, RDF.type, CRM['E22_Man-Made_Object']))
        self.graph.add((myphoto, RDF.type, FENTRY.Photograph))
        self.graph.add((myphoto, CRM.P1_is_identified_by, Literal(self.entry_id)))
        self.graph.add((self.myentry, CRM.P70_documents, myphoto))
        self.graph.add((myphoto, CRM.P70i_is_documented_in, self.myentry))
        self.graph.add((self.myentry, FENTRY.describes, myphoto))
        production = FZERI_FENTRY[self.entry_id + '/photo/production']
        self.graph.add((production, RDF.type, CRM.E12_Production))
        self.graph.add((production, CRM.P108_produced, myphoto))
        self.graph.add((myphoto, CRM.P108i_was_produced_by, production))
        artwork = FZERI_OAENTRY[self.oaentry_id + '/artwork']
        self.graph.add((artwork, RDF.type, CRM.E1_CRM_Entity))
        self.graph.add((artwork, CRM.P1_is_identified_by, Literal(self.oaentry_id)))

    # begin COPYRIGHT paragraph
    # COPYRIGHT contains only one field
    # example:
    #     CPRD: PI_0219/4/7
    def parse_paragraph_copyright(self, paragraph):
        copyright_exp_date = FZERI_FENTRY[self.entry_id + '/copyright']
        self.graph.add((copyright_exp_date, RDF.type, CRM.E30_Right))
        if paragraph.find("CRPD") is not None:
            self.graph.add((copyright_exp_date, CRM.P3_has_note, Literal(paragraph.find("CRPD").text)))
        self.graph.add((copyright_exp_date, CRM.P104i_applies_to, self.myentry))
        self.graph.add((self.myentry, CRM.P104_is_subject_to, copyright_exp_date))
        ### end COPYRIGHT paragraph

    # begin NOTES paragraph
    # NOTES contains only one field
    # example:
    #     OSS: Incollata su cartone delle stesse misure.
    def parse_paragraph_notes(self, paragraph):
        self.graph.add((self.myentry, CRM.P3_has_note, Literal(paragraph.find("OSS").text)))
        ### end NOTES paragraph

    # begin SUPERVISOR paragraph
    # SUPERVISOR contains only one field
    # example:
    #     FUR: Giudici C.
    def parse_paragraph_supervisor(self, paragraph):
        node = paragraph.find("FUR")
        if node is None:
            return
        supervisor = FZERI_FENTRY[self.entry_id + '/supervisor']
        self.graph.add((supervisor, RDF.type, CRM.E39_Actor))
        self.graph.add((supervisor, RDF.type, FOAF.Agent))
        self.graph.add((supervisor, RDFS.label, Literal(node.text)))
        self.graph.add((supervisor, FOAF.name, Literal(node.text)))
        creation = FZERI_FENTRY[self.entry_id + '/cataloguing']
        self.graph.add((creation, RDF.type, CRM.E65_Creation))
        self.graph.add((creation, CRM.P11_had_participant, supervisor))
        self.graph.add((supervisor, CRM.P11i_participated_in, creation))
        self.graph.add((self.myentry, RDF.type, FOAF.Document))
        role = FZERI_FENTRY[self.entry_id + '/supervisor/role']
        self.graph.add((role, RDF.type, PRO.roleInTime))
        self.graph.add((role, PRO.withRole, Literal("supervisor")))
        self.graph.add((role, PRO.relatesToDocument, self.myentry))
        self.graph.add((supervisor, PRO.holdsRoleInTime, role))
        self.graph.add((creation, CRM.P94_created, self.myentry))
        self.graph.add((self.myentry, CRM.P94i_was_created_by, creation))
        ### end SUPERVISOR paragraph

    # begin CLASSIFICATION paragraph
    # example:
    #     UBFU: Girolamo di Benvenuto 2
    #     UBFT: Pittura italiana sec. XV. Siena. Benvenuto di Giovanni, Girolamo di Benvenuto
    #     UBFS: Pittura italiana
    #     UBFP: Fototeca  Zeri
    #     INVN: 45423
    #     SERCD: 67680
    #     UBFF: 5
    #     UBFC: PI_0199/5/42
    #     SERCDOA: 19030
    #     UBFN: 0199
    def parse_paragraph_classification(self, paragraph):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        collection = serie = box = issue = None
        for node in paragraph:
            if node.tag == "SERCDOA":
                self.graph.add((self.myentry, CRM.P67_refers_to, FZERI_OAENTRY[node.text]))
            elif node.tag == "INVN":
                inv = FZERI_FENTRY[self.entry_id + '/inventory/' + node.text]
                self.graph.add((inv, RDF.type, CRM.E42_Identifier))
                self.graph.add((inv, RDFS.label, Literal(node.text)))
                self.graph.add((inv, CRM.P149i_identifies, myphoto))
                self.graph.add((myphoto, CRM.P149_is_identified_by, inv))
            elif node.tag == "UBFP":
                collection = FZERI_COLLECTION[sha1(node.text.encode('utf-8')).hexdigest()]
                self.graph.add((collection, RDF.type, CRM.E53_Place))
                self.graph.add((collection, CRM.P87_is_identified_by, Literal(node.text)))
            elif node.tag == "UBFS":
                serie = FZERI_SERIE[sha1(node.text.encode('utf-8')).hexdigest()]
                self.graph.add((serie, RDF.type, CRM.E53_Place))
                self.graph.add((serie, CRM.P87_is_identified_by, Literal(node.text)))
            elif node.tag == "UBFT":
                box = FZERI_BOX[sha1(node.text.encode('utf-8')).hexdigest() +
                                "/" + paragraph.find("UBFN").text]
                self.graph.add((box, RDF.type, CRM.E53_Place))
                self.graph.add((box, CRM.P87_is_identified_by, Literal(node.text)))
                self.graph.add((box, CRM.P87_is_identified_by, Literal(paragraph.find("UBFN").text)))
            elif node.tag == "UBFU":
                issue = FZERI_BOX[sha1(node.text.encode('utf-8')).hexdigest() +
                                  "/" + paragraph.find("UBFF").text]
                self.graph.add((issue, RDF.type, CRM.E53_Place))
                self.graph.add((issue, CRM.P87_is_identified_by, Literal(node.text)))
                self.graph.add((issue, CRM.P87_is_identified_by, Literal(paragraph.find("UBFF").text)))
                self.graph.add((issue, CRM.P54i_is_current_permanent_location_of, myphoto))
                self.graph.add((myphoto, CRM.P54_has_current_permanent_location, issue))
            elif node.tag == "UBFC":
                self.graph.add((myphoto, CRM.P54_has_current_permanent_location, Literal(node.text)))
        contained = issue
        for container in box, serie, collection:
            if container:
                self.graph.add((container, CRM.P59_has_section, contained))
                self.graph.add((contained, CRM.P59i_is_located_on_or_within, container))
                contained = container
        ### end CLASSIFICATION paragraph

    # begin OWNERSHIP paragraph
    # example:
    #     CDGG: proprietà Ente pubblico non territoriale
    #     CDGS: Alma Mater Studiorum Università di Bologna
    def parse_paragraph_ownership(self, paragraph):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        acquisition = FZERI_FENTRY[self.entry_id + '/photo/ownership']
        self.graph.add((acquisition, RDF.type, CRM.E8_Acquisition))
        self.graph.add((acquisition, CRM.P24_transferred_title_of, myphoto))
        self.graph.add((myphoto, CRM.P24i_changed_ownership_through, acquisition))
        for node in paragraph:
            if node.tag == "CDGS":
                actor = FZERI_FENTRY[self.entry_id + '/photo/ownership/owner']
                self.graph.add((actor, RDF.type, CRM.E39_Actor))
                self.graph.add((actor, RDFS.label, Literal(node.text)))
                self.graph.add((actor, CRM.P22i_acquired_title_through, acquisition))
                self.graph.add((acquisition, CRM.P22_transferred_title_to, actor))
            elif node.tag == "CDGG":
                acquisition = FZERI_FENTRY[self.entry_id + '/photo/ownership']
                self.graph.add((acquisition, CRM.P3_has_note, Literal(node.text)))
        ### end OWNERSHIP paragraph

    # begin CODES paragraph
    # example:
    #     NCTR: 08
    #     ESC: Fondazione Federico Zeri - Università di Bologna
    #     TSK: F
    #     LIR: I
    # TODO: LIR field has yet to be mapped
    def parse_paragraph_codes(self, paragraph):
        for node in paragraph:
            if node.tag == "TSK":
                entry_type = FZERI_ENTRYTYPE[node.text]
                self.graph.add((entry_type, RDF.type, CRM.E55_Type))
                self.graph.add((entry_type, RDFS.label, Literal(node.text)))
                self.graph.add((self.myentry, CRM.P2_has_type, entry_type))
                self.graph.add((entry_type, CRM.P2i_is_type_of, self.myentry))
            elif node.tag == "NCTN":
                identifier = FZERI_FENTRY[self.entry_id + '/id_number']
                self.graph.add((identifier, RDF.type, CRM.E42_Identifier))
                self.graph.add((identifier, RDFS.label, Literal(node.text)))
                self.graph.add((identifier, CRM.P2_has_type, FZERI_IDENTIFIER.id_number))
                self.graph.add((FZERI_IDENTIFIER.id_number, CRM.P2i_is_type_of, identifier))
                self.graph.add((self.myentry, CRM.P48_has_preferred_identifier, identifier))
                self.graph.add((identifier, CRM.P48i_is_preferred_identifier_of, self.myentry))
            elif node.tag == "NCTR":
                identifier = FZERI_FENTRY[self.entry_id + '/regional_code']
                self.graph.add((identifier, RDF.type, CRM.E42_Identifier))
                self.graph.add((identifier, RDFS.label, Literal(node.text)))
                self.graph.add((identifier, CRM.P2_has_type, FZERI_IDENTIFIER.regional_code))
                self.graph.add((FZERI_IDENTIFIER.regional_code, CRM.P2i_is_type_of, identifier))
                self.graph.add((identifier, CRM.P48i_is_preferred_identifier_of, self.myentry))
                self.graph.add((self.myentry, CRM.P48_has_preferred_identifier, identifier))
            elif node.tag == "ESC":
                actor = FZERI_FENTRY[self.entry_id + '/keeper']
                self.graph.add((actor, RDF.type, CRM.E40_Legal_Body))
                self.graph.add((actor, RDF.type, FOAF.Agent))
                self.graph.add((actor, FOAF.name, Literal(node.text)))
                role = FZERI_FENTRY[self.entry_id + '/keeper/role']
                self.graph.add((role, RDF.type, PRO.roleInTime))
                self.graph.add((role, PRO.withRole, Literal("keeper")))
                self.graph.add((role, PRO.relatesToDocument, self.myentry))
                self.graph.add((actor, CRM.P50i_is_current_keeper_of, self.myentry))
                self.graph.add((self.myentry, CRM.P50_has_current_keeper, actor))
            # TODO: LIR has yet to be mapped
            elif node.tag == "LIR":
                pass
        ### end CODES paragraph

    # begin CATALOGUING paragraph
    # example:
    #     CMPD: 10/10/2005 0.00.00
    #     CMPN: Erika Giuliani
    def parse_paragraph_cataloguing(self, paragraph):
        creation = FZERI_FENTRY[self.entry_id + '/cataloguing']
        self.graph.add((creation, RDF.type, CRM.E65_Creation))
        for node in paragraph:
            if node.tag == "CMPD":
                timespan = FZERI_FENTRY[self.entry_id + '/cataloguing/ts']
                self.graph.add((timespan, RDF.type, CRM['E52_Time-Span']))
                date = FZERI_FENTRY[self.entry_id + '/cataloguing/date']
                self.graph.add((date, RDF.type, CRM.E49_Time_Appellation))
                self.graph.add((date, RDFS.label, Literal(node.text)))
                self.graph.add((date, CRM.P78i_identifies, timespan))
                self.graph.add((timespan, CRM.P78_is_identified_by, date))
                self.graph.add((timespan, CRM['P4i_is_time-span_of'], timespan))
                self.graph.add((creation, CRM['P4_has_time-span'], timespan))
            elif node.tag == "CMPN":
                actor = FZERI_FENTRY[self.entry_id + '/cataloguing/actor']
                self.graph.add((actor, RDF.type, CRM.E39_Actor))
                self.graph.add((actor, RDFS.label, Literal(node.text)))
                self.graph.add((actor, CRM.P14i_performed, creation))
                self.graph.add((creation, CRM.P14_carried_out_by, actor))
        self.graph.add((creation, CRM.P94_created, self.myentry))
        self.graph.add((self.myentry, CRM.P94i_was_created_by, creation))
        ### end CATALOGUING paragraph

    # begin UPDATING paragraph
    # example:
    #     AGGD: 09/10/2012
    #     AGGN: Marcello Rossini
    def parse_paragraph_updating(self, paragraph, rep):
        transformation = FZERI_FENTRY[self.entry_id + '/cataloguing/update/' + str(rep)]
        self.graph.add((transformation, RDF.type, CRM.E81_Transformation))
        for node in paragraph:
            if node.tag == "AGGD":
                timespan = FZERI_FENTRY[self.entry_id + '/cataloguing/update/' + str(rep) + '/ts']
                self.graph.add((timespan, RDF.type, CRM['E52_Time-Span']))
                self.graph.add((timespan, CRM['P4i_is_time-span_of'], transformation))
                self.graph.add((transformation, CRM['P4_has_time-span'], timespan))
                date = FZERI_FENTRY[self.entry_id + '/cataloguing/update/' + str(rep) + '/date']
                self.graph.add((date, RDF.type, CRM.E49_Time_Appellation))
                self.graph.add((date, RDFS.label, Literal(node.text)))
                self.graph.add((date, CRM.P78i_identifies, timespan))
                self.graph.add((timespan, CRM.P78_is_identified_by, date))
            elif node.tag == "AGGN":
                actor = FZERI_FENTRY[self.entry_id + '/cataloguing/update/' + str(rep) + '/actor']
                self.graph.add((actor, RDF.type, CRM.E39_Actor))
                self.graph.add((actor, RDFS.label, Literal(node.text)))
                self.graph.add((actor, CRM.P11i_participated_in, transformation))
                self.graph.add((transformation, CRM.P11_had_participant, actor))
        self.graph.add((transformation, CRM.P124_transformed, self.myentry))
        self.graph.add((self.myentry, CRM.P124i_was_transformed_by, transformation))
        ### end UPDATING paragraph

    # begin OBJECT paragraph
    # example:
    #     MISO: supporto primario
    #     MTX: BN
    #     QNTN: 1
    #     OGTS: assemblaggio
    #     MISD: 240
    #     MISA: 215
    #     MISL: 165
    #     OGTB: m
    #     MTC: gelatina ai sali d'argento/ carta baritata
    #     MISU: mm
    #     OGTD: positivo
    def parse_paragraph_object(self, paragraph):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        dimensions = {"MISA": "height", "MISL": "width", "MISD": "diameter"}
        for node in paragraph:
            if node.tag == "OGTD":
                self.graph.add((myphoto, CRM.P2_has_type, Literal(node.text)))
            elif node.tag == "QNTN":
                self.graph.add((myphoto, CRM.P57_has_number_of_parts, Literal(node.text)))
            elif node.tag == "OGTB":
                self.graph.add((myphoto, DC.type, Literal(node.text)))
            elif node.tag == "OGTS":
                self.graph.add((myphoto, DC['format'], FZERI_PHOTOFORMAT[quote_plus(node.text)]))
            elif node.tag == "MTX":
                self.graph.add((myphoto, DC['format'], FZERI_PHOTOCOLOR[quote_plus(node.text)]))
            elif node.tag == "MTC":
                self.graph.add((myphoto, CRM.P45_consists_of, FZERI_MATERIAL[quote_plus(node.text)]))
                self.graph.add((FZERI_MATERIAL[quote_plus(node.text)], CRM.P45i_is_incorporated_in,
                                myphoto))
            elif node.tag in dimensions.keys():
                dimension = FZERI_FENTRY[self.entry_id + '/photo/' + dimensions[node.tag]]
                self.graph.add((dimension, RDF.type, CRM.E54_Dimension))
                self.graph.add((dimension, CRM.P2_has_type, FZERI_DIMENSION[dimensions[node.tag]]))
                self.graph.add((FZERI_DIMENSION[dimensions[node.tag]], CRM.P2i_is_type_of, dimension))
                self.graph.add((dimension, CRM.P90_has_value, Literal(node.text)))
                if paragraph.find("MISU") is not None:
                    self.graph.add((dimension, CRM.P91_has_unit,
                                    unit_fzeri_to_qudt[paragraph.find("MISU").text]))
                    self.graph.add((unit_fzeri_to_qudt[paragraph.find("MISU").text],
                                    CRM.P91i_is_unit_of, dimension))
                if paragraph.find("MISO") is not None:
                    self.graph.add((dimension, CRM.P2_has_type,
                                    FZERI_DIMENSION[quote_plus(paragraph.find("MISO").text)]))
                    self.graph.add((FZERI_DIMENSION[quote_plus(paragraph.find("MISO").text)],
                                    CRM.P2i_is_type_of, dimension))
                self.graph.add((dimension, CRM.P43i_is_dimension_of, myphoto))
                self.graph.add((myphoto, CRM.P43_has_dimension, dimension))

    # begin SUBJECT paragraph
    # example:
    #     SGLA: Girolamo di Benvenuto (Girolamo del Guasta) - sec. XVI - Madonna con Bambino e san Giovannino
    #     FTAT: insieme
    #     SGLL: Alessandro Botticelli (1446-1510). Madonna m.d. Christusknaben u.d. kleinen Johannes
    #     SGTI: Madonna con Bambino e san Giovannino
    #     SGLT: School of Sano di Pietro. Madonna and Child with Saints
    #     SGLS: del catalogatore
    #     OGTD: dipinto
    def parse_paragraph_subject(self, paragraph):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        depicted_subject = FZERI_FENTRY[self.entry_id + '/photo/subject']
        subj_title = FZERI_FENTRY[self.entry_id + '/photo/subject/title']
        self.graph.add((subj_title, RDF.type, CRM.E35_Title))
        self.graph.add((subj_title, RDF.type, DCTERMS.title))
        self.graph.add((depicted_subject, RDF.type, CRM.E1_CRM_Entity))
        self.graph.add((depicted_subject, CRM.P62i_is_depicted_by, myphoto))
        self.graph.add((myphoto, CRM.P62_depicts, depicted_subject))
        for node in paragraph:
            if node.tag == "SGTI":
                self.graph.add((depicted_subject, CRM.P1_is_identified_by, Literal(node.text)))
            elif node.tag == "SGLT":
                self.graph.add((subj_title, RDFS.label, Literal(node.text)))
                self.graph.add((subj_title, FENTRY.isProperTitleOf, depicted_subject))
                self.graph.add((depicted_subject, FENTRY.hasProperTitle, subj_title))
            elif node.tag == "SGLL":
                self.graph.add((subj_title, RDFS.label, Literal(node.text)))
                self.graph.add((subj_title, FENTRY.isParallelTitleOf, depicted_subject))
                self.graph.add((depicted_subject, FENTRY.hasParallelTitle, subj_title))
            elif node.tag == "SGLA":
                self.graph.add((subj_title, RDFS.label, Literal(node.text)))
                self.graph.add((subj_title, FENTRY.isAttributedTitleOf, depicted_subject))
                self.graph.add((depicted_subject, FENTRY.hasAttributedTitle, subj_title))
            elif node.tag == "SGLS":
                self.graph.add((subj_title, CRM.P3_has_note, Literal(node.text)))
            elif node.tag == "FTAT":
                self.graph.add((depicted_subject, CRM.P3_has_note, Literal(node.text)))
            elif node.tag == "OGTD":
                self.graph.add((depicted_subject, CRM.P2_has_type, Literal(node.text)))
        ### end SUBJECT paragraph

    # begin AUTHOR paragraph
    # example:
    #     AUTN: Girolamo di Benvenuto
    #     AUTB: Scuola italiana, scuola toscana, scuola senese
    #     AUTP: Girolamo del Guasta
    #     AUTI: Palmezzano Marco (?)
    def parse_paragraph_author(self, paragraph, rep):
        # TODO: isn't it already described in the actual artwork?
        artwork = FZERI_OAENTRY[self.oaentry_id + '/artwork']
        production = FZERI_OAENTRY[self.oaentry_id + '/artwork/production/' + str(rep)]
        self.graph.add((production, RDF.type, CRM.E12_Production))
        self.graph.add((production, CRM.P108_produced, artwork))
        self.graph.add((artwork, CRM.P108i_was_produced_by, production))
        actor = FZERI_OAENTRY[self.oaentry_id + '/artwork/production/' + str(rep) + '/author']
        self.graph.add((actor, RDF.type, CRM.E39_Actor))
        self.graph.add((actor, CRM.P14i_performed, production))
        self.graph.add((production, CRM.P14_carried_out_by, actor))
        # TODO: add PROV-O relations (as specified in TPDL paper)
        for node in paragraph:
            if node.tag == "AUTN":
                proper_name = FZERI_OAENTRY[self.oaentry_id + '/artwork/production/' + str(rep) + '/author/proper_name']
                self.graph.add((proper_name, RDF.type, CRM.E82_Actor_Appellation))
                self.graph.add((proper_name, RDFS.label, Literal(node.text)))
                self.graph.add((proper_name, CRM.P131i_identifies, actor))
                self.graph.add((actor, CRM.P131_is_identified_by, proper_name))
            elif node.tag == "AUTP":
                pseudonym = FZERI_OAENTRY[self.oaentry_id + '/artwork/production/' + str(rep) + '/author/pseudonym']
                self.graph.add((pseudonym, RDF.type, CRM.E82_Actor_Appellation))
                self.graph.add((pseudonym, RDFS.label, Literal(node.text)))
                self.graph.add((pseudonym, CRM.P131i_identifies, actor))
                self.graph.add((actor, CRM.P131_is_identified_by, pseudonym))
            elif node.tag == "AUTI":
                other_name = FZERI_OAENTRY[self.oaentry_id + '/artwork/production/' + str(rep) + '/author/other_name']
                self.graph.add((other_name, RDF.type, CRM.E82_Actor_Appellation))
                self.graph.add((other_name, RDFS.label, Literal(node.text)))
                self.graph.add((other_name, CRM.P131i_identifies, actor))
                self.graph.add((actor, CRM.P131_is_identified_by, other_name))
            elif node.tag == "AUTB":
                context = FZERI_OAENTRY[self.oaentry_id + '/artwork/production/' + str(rep) + '/author/context']
                self.graph.add((context, RDF.type, CRM.E62_String))
                self.graph.add((context, RDFS.label, Literal(node.text)))
                self.graph.add((actor, FENTRY.hasCulturalContext, context))
                self.graph.add((context, FENTRY.isCulturalContextOf, actor))
        ### end AUTHOR paragraph

    # begin DATING paragraph
    # example:
    #     DTSV: ca.
    #     DTMM: iscrizione
    #     DTSF: 1967
    #     DTZG: XX
    #     DTMS: fotografia eseguita in occasione della vendita all'asta nel 1961
    #     DTSL: ca.
    #     DTSI: 1967
    def parse_paragraph_dating(self, paragraph):
        production = FZERI_FENTRY[self.entry_id + '/photo/production']
        p_production = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter)]
        self.graph.add((p_production, RDF.type, CRM.E12_Production))
        self.graph.add((p_production, CRM.P9i_forms_part_of, production))
        self.graph.add((production, CRM.P9_consists_of, p_production))
        timespan = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter) + '/date']
        self.graph.add((timespan, RDF.type, CRM['E52_Time-Span']))
        self.graph.add((timespan, CRM['P4i_is_time-span_of'], p_production))
        self.graph.add((p_production, CRM['P4_has_time-span'], timespan))
        for node in paragraph:
            if node.tag == "DTZG":
                century = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                       str(self.production_counter) + '/date/century']
                self.graph.add((century, RDF.type, CRM.E49_Time_Appellation))
                self.graph.add((century, RDFS.label, Literal(node.text)))
                self.graph.add((century, CRM.P78i_identifies, timespan))
                self.graph.add((timespan, CRM.P78_is_identified_by, century))
            elif node.tag == "DTSI":
                begin = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                     str(self.production_counter) + '/date/begin']
                self.graph.add((begin, RDF.type, TIME.Instant))
                self.graph.add((begin, TIME.inXSDDateTime, Literal(node.text)))
                self.graph.add((timespan, RDF.type, TIME.TemporalEntity))
                self.graph.add((timespan, TIME.hasBeginning, begin))
                if paragraph.find("DTSV") is not None:
                    self.graph.add((timespan, CRM.P79_beginning_is_qualified_by, Literal(paragraph.find("DTSV").text)))
            elif node.tag == "DTSF":
                end = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                   str(self.production_counter) + '/date/end']
                self.graph.add((end, RDF.type, TIME.Instant))
                self.graph.add((end, TIME.inXSDDateTime, Literal(node.text)))
                self.graph.add((timespan, RDF.type, TIME.TemporalEntity))
                self.graph.add((timespan, TIME.hasEnd, end))
                if paragraph.find("DTSL") is not None:
                    self.graph.add((timespan, CRM.P80_end_is_qualified_by, Literal(paragraph.find("DTSL").text)))
            elif node.tag == "DTMM":
                assignment = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                          str(self.production_counter) + '/assignment']
                self.graph.add((assignment, RDF.type, CRM.E13_Attribute_Assignment))
                self.graph.add((assignment, CRM.P17_was_motivated_by, Literal(node.text)))
                self.graph.add((assignment, CRM.P141_assigned, timespan))
                self.graph.add((timespan, CRM.P141i_was_assigned_by, assignment))
                self.graph.add((assignment, CRM.P140_assigned_attribute_to, p_production))
                self.graph.add((p_production, CRM.P140i_was_attributed_by, assignment))
            elif node.tag == "DTMS":
                self.graph.add((p_production, CRM.P3_has_note, Literal(node.text)))
        self.production_counter += 1
        ### end DATING paragraph

    # begin PHOTOGRAPHER paragraph
    # example:
    #     AUFI: The Art Institute of Chicago. Photograph Department
    #     AUFK: numero di inventario
    #     AUFM: n.r.
    #     AUFN: Anonimo
    #     AUFA: Edizioni Brogi
    #     AUFR: fotografo principale
    #     AUFS: studio
    def parse_paragraph_photographer(self, paragraph, rep):
        production = FZERI_FENTRY[self.entry_id + '/photo/production']
        p_production = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter)]
        self.graph.add((p_production, RDF.type, CRM.E12_Production))
        self.graph.add((p_production, CRM.P9i_forms_part_of, production))
        self.graph.add((production, CRM.P9_consists_of, p_production))
        actor = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter) + '/photographer']
        self.graph.add((actor, RDF.type, CRM.E39_Actor))
        self.graph.add((actor, CRM.P14_performed, p_production))
        self.graph.add((p_production, CRM.P14_carried_out_by, actor))
        for node in paragraph:
            if node.tag == "AUFN":
                proper_name = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                           str(self.production_counter) + '/photographer/proper_name']
                self.graph.add((proper_name, RDF.type, CRM.E82_Actor_Appellation))
                self.graph.add((proper_name, RDFS.label, Literal(node.text)))
                self.graph.add((actor, CRM.P131_is_identified_by, proper_name))
            elif node.tag == "AUFI":
                # TODO: add VCard Ontology
                address = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                       str(self.production_counter) + '/photographer/address']
                self.graph.add((address, RDF.type, CRM.E51_Contact_Point))
                self.graph.add((address, RDFS.label, Literal(node.text)))
                self.graph.add((actor, CRM.P76_has_contact_point, address))
            elif node.tag == "AUFM":
                try:
                    attribute_assignment
                except UnboundLocalError:
                    attribute_assignment = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                                        str(self.production_counter) + '/photographer/assignment']
                    self.graph.add((attribute_assignment, RDF.type, CRM.E13_Attribute_Assignment))
                    self.graph.add((attribute_assignment, CRM.P141_assigned, actor))
                    self.graph.add((actor, CRM.P141i_was_assigned_by, attribute_assignment))
                    self.graph.add((attribute_assignment, CRM.P140_assigned_attribute_to, p_production))
                    self.graph.add((p_production, CRM.P140i_was_attributed_by, attribute_assignment))
                self.graph.add((attribute_assignment, CRM.P17_was_motivated_by, Literal(node.text)))
            elif node.tag == "AUFK":
                try:
                    attribute_assignment
                except UnboundLocalError:
                    attribute_assignment = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                                        str(self.production_counter) + '/photographer/assignment']
                    self.graph.add((attribute_assignment, RDF.type, CRM.E13_Attribute_Assignment))
                    self.graph.add((attribute_assignment, CRM.P141_assigned, actor))
                    self.graph.add((actor, CRM.P141i_was_assigned_by, attribute_assignment))
                    self.graph.add((attribute_assignment, CRM.P140_assigned_attribute_to, p_production))
                    self.graph.add((p_production, CRM.P140i_was_attributed_by, attribute_assignment))
                self.graph.add((attribute_assignment, CRM.P16_used_specific_object, Literal(node.text)))
            elif node.tag == "AUFA":
                self.graph.add((actor, CRM.P3_has_note, Literal(node.text)))
            elif node.tag == "AUFS":
                self.graph.add((actor, CRM.P2_has_type, Literal(node.text)))
            elif node.tag == "AUFR":
                self.graph.add((actor, RDF.type, FOAF.Agent))
                myphoto = FZERI_FENTRY[self.entry_id + '/photo']
                self.graph.add((myphoto, RDF.type, FOAF.Document))
                role = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                    str(self.production_counter) + '/photographer/role']
                self.graph.add((role, RDF.type, PRO.roleInTime))
                self.graph.add((role, PRO.withRole, Literal(node.text)))
                self.graph.add((role, PRO.relatesToDocument, myphoto))
                self.graph.add((actor, PRO.holdsRoleInTime, role))
        self.production_counter += 1
        ### end PHOTOGRAPHER paragraph

    # begin PRODUCTION AND PUBLISHING paragraph
    # example:
    #     PDFK: 3071
    #     PDFI: Christies
    #     PDFN: Procacci, Michele
    #     PDFL: Londra
    #     PDFM: timbro
    #     PDFB: Christie's
    #     SFIT: L'Umbria Illustrata
    #     PDFD: 1980
    #     EDIT: Tilli - Perugia
    #     PDFR: committente
    def parse_paragraph_production_and_publishing(self, paragraph, rep):
        production = FZERI_FENTRY[self.entry_id + '/photo/production']
        p_production = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter)]
        self.graph.add((p_production, RDF.type, CRM.E12_Production))
        self.graph.add((p_production, CRM.P9i_forms_part_of, production))
        self.graph.add((production, CRM.P9_consists_of, p_production))
        publisher = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter) + '/publisher']
        self.graph.add((publisher, RDF.type, CRM.E39_Actor))
        self.graph.add((publisher, CRM.P14_performed, p_production))
        self.graph.add((p_production, CRM.P14_carried_out_by, publisher))
        for node in paragraph:
            if node.tag == "PDFN":
                proper_name = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                           str(self.production_counter) + '/publisher/proper_name']
                self.graph.add((proper_name, RDF.type, CRM.E82_Actor_Appellation))
                self.graph.add((proper_name, RDFS.label, Literal(node.text)))
                self.graph.add((publisher, CRM.P131_is_identified_by, proper_name))
            elif node.tag == "PDFB":
                corporate_name = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                              str(self.production_counter) + '/publisher/corporate_name']
                self.graph.add((corporate_name, RDF.type, CRM.E82_Actor_Appellation))
                self.graph.add((corporate_name, RDFS.label, Literal(node.text)))
                self.graph.add((publisher, CRM.P131_is_identified_by, corporate_name))
            elif node.tag == "PDFI":
                # TODO: add VCard Ontology
                address = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                       str(self.production_counter) + '/publisher/address']
                self.graph.add((address, RDF.type, CRM.E51_Contact_Point))
                self.graph.add((address, RDFS.label, Literal(node.text)))
                self.graph.add((publisher, CRM.P76_has_contact_point, address))
            elif node.tag == "PDFM":
                try:
                    attribute_assignment
                except UnboundLocalError:
                    attribute_assignment = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                                        str(self.production_counter) + '/publisher/assignment']
                    self.graph.add((attribute_assignment, RDF.type, CRM.E13_Attribute_Assignment))
                    self.graph.add((attribute_assignment, CRM.P141_assigned, publisher))
                    self.graph.add((publisher, CRM.P141i_was_assigned_by, attribute_assignment))
                    self.graph.add((attribute_assignment, CRM.P140_assigned_attribute_to, p_production))
                    self.graph.add((p_production, CRM.P140i_was_attributed_by, attribute_assignment))
                self.graph.add((attribute_assignment, CRM.P17_was_motivated_by, Literal(node.text)))
            elif node.tag == "PDFK":
                try:
                    attribute_assignment
                except UnboundLocalError:
                    attribute_assignment = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                                        str(self.production_counter) + '/publisher/assignment']
                    self.graph.add((attribute_assignment, RDF.type, CRM.E13_Attribute_Assignment))
                    self.graph.add((attribute_assignment, CRM.P141_assigned, publisher))
                    self.graph.add((publisher, CRM.P141i_was_assigned_by, attribute_assignment))
                    self.graph.add((attribute_assignment, CRM.P140_assigned_attribute_to, p_production))
                    self.graph.add((p_production, CRM.P140i_was_attributed_by, attribute_assignment))
                self.graph.add((attribute_assignment, CRM.P16_used_specific_object, Literal(node.text)))
            elif node.tag == "PDFR":
                self.graph.add((publisher, RDF.type, FOAF.Agent))
                myphoto = FZERI_FENTRY[self.entry_id + '/photo']
                self.graph.add((myphoto, RDF.type, FOAF.Document))
                role = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                    str(self.production_counter) + '/photographer/role']
                self.graph.add((role, RDF.type, PRO.roleInTime))
                self.graph.add((role, PRO.withRole, Literal(node.text)))
                self.graph.add((role, PRO.relatesToDocument, myphoto))
                self.graph.add((publisher, PRO.holdsRoleInTime, role))
            elif node.tag == "PDFL":
                location = FZERI_FENTRY[self.entry_id + '/photo/production/' +
                                        str(self.production_counter) + '/publisher/location']
                self.graph.add((location, RDF.type, CRM.E53_Place))
                self.graph.add((location, RDFS.label, Literal(node.text)))
                self.graph.add((p_production, CRM.P7_took_place_at, location))
            elif node.tag == "PDFD":
                timespan = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter) + '/date']
                self.graph.add((timespan, RDF.type, CRM['E52_Time-Span']))
                date = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter) + '/date/year']
                self.graph.add((date, RDF.type, CRM.E49_Time_Appellation))
                self.graph.add((date, RDFS.label, Literal(node.text)))
                self.graph.add((date, CRM.P78i_identifies, timespan))
                self.graph.add((timespan, CRM.P78_is_identified_by, date))
                self.graph.add((timespan, CRM['P4i_is_time-span_of'], p_production))
                self.graph.add((p_production, CRM['P4_has_time-span'], timespan))
            # TODO: EDIT has yet to be mapped
            elif node.tag == "EDIT":
                # edition = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter) + '/edition']
                # self.graph.add((edition, RDF.type, CRM['E52_Time-Span']))
                # self.graph.add((edition, RDFS.label, Literal(node.text)))
                # self.graph.add((edition, CRM['P4i_is_time-span_of'], p_production))
                # self.graph.add((p_production, CRM['P4_has_time-span'], edition))
                pass
            # TODO: SFIT has yet to be mapped
            elif node.tag == "SFIT":
                pass
        self.production_counter += 1
        ### end PRODUCTION AND PUBLISHING paragraph

    # begin PLACE AND DATE OF THE SHOT paragraph
    # example:
    #     LRA: Londra
    #     LRCC: Roma
    #     LRCS: Regno Unito
    #     LRD: 1967
    #     LRO: Asta Christie's 11/07/1980
    def parse_paragraph_place_and_date_of_the_shot(self, paragraph):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        creation = FZERI_FENTRY[self.entry_id + '/photo/creation']
        self.graph.add((creation, RDF.type, CRM.E65_Creation))
        self.graph.add((creation, CRM.P94_created, myphoto))
        self.graph.add((myphoto, CRM.P94i_was_created_by, creation))
        country = village = None
        for node in paragraph:
            if node.tag == "LRD":
                timespan = FZERI_FENTRY[self.entry_id + '/photo/creation/date']
                self.graph.add((timespan, RDF.type, CRM['E52_Time-Span']))
                date = FZERI_FENTRY[self.entry_id + '/photo/creation/date/year']
                self.graph.add((date, RDF.type, CRM.E49_Time_Appellation))
                self.graph.add((date, RDFS.label, Literal(node.text)))
                self.graph.add((date, CRM.P78i_identifies, timespan))
                self.graph.add((timespan, CRM.P78_is_identified_by, date))
                self.graph.add((timespan, CRM['P4i_is_time-span_of'], creation))
                self.graph.add((creation, CRM['P4_has_time-span'], timespan))
            elif node.tag == "LRCS":
                country = FZERI_FENTRY[self.entry_id + '/photo/creation/country']
                self.graph.add((country, RDF.type, CRM.E53_Place))
                self.graph.add((country, RDFS.label, Literal(node.text)))
            elif node.tag == "LRCC" or node.tag == "LRA":
                village = FZERI_FENTRY[self.entry_id + '/photo/creation/village']
                self.graph.add((village, RDF.type, CRM.E53_Place))
                self.graph.add((village, RDFS.label, Literal(node.text)))
            elif node.tag == "LRO":
                occasion = FZERI_FENTRY[self.entry_id + '/photo/creation/occasion']
                self.graph.add((occasion, RDF.type, CRM.E4_Period))
                self.graph.add((occasion, RDFS.label, Literal(node.text)))
                self.graph.add((occasion, CRM.P10i_contains, creation))
                self.graph.add((creation, CRM.P10_falls_within, occasion))
        if country and village:
            self.graph.add((country, CRM.P89i_contains, village))
            self.graph.add((village, CRM.P89_falls_within, country))
            self.graph.add((village, CRM.P7i_witnessed, creation))
            self.graph.add((creation, CRM.P7_took_place_at, village))
        elif country:
            self.graph.add((country, CRM.P7i_witnessed, creation))
            self.graph.add((creation, CRM.P7_took_place_at, country))
        elif village:
            self.graph.add((village, CRM.P7i_witnessed, creation))
            self.graph.add((creation, CRM.P7_took_place_at, village))
        ### end PLACE AND DATE OF THE SHOT paragraph

    # begin RELATIONS WITH OTHER PHOTOGRAPHIC OBJECTS (NEGATIVE) paragraph
    # example:
    #     ROFC: Bologna/ Fondazione Federico Zeri - Università di Bologna/ Fototeca Zeri
    #     ROFI: C 6133
    #     ROFO: negativo
    #     ROFF: positivo
    def parse_paragraph_relations_with_other_photographic_objects_negative(self, paragraph):
        production = FZERI_FENTRY[self.entry_id + '/photo/production']
        p_production = FZERI_FENTRY[self.entry_id + '/photo/production/' + str(self.production_counter)]
        self.graph.add((p_production, RDF.type, CRM.E12_Production))
        self.graph.add((p_production, CRM.P9i_forms_part_of, production))
        self.graph.add((production, CRM.P9_consists_of, p_production))
        negative = FZERI_NEGATIVE[self.negative_id]
        self.graph.add((negative, RDF.type, CRM['E22_Man-Made_Object']))
        self.graph.add((negative, CRM.P1_is_identified_by, Literal(self.negative_id)))
        self.graph.add((p_production, CRM.P16_used_specific_object, negative))
        self.graph.add((negative, CRM.P16i_was_used_for, p_production))
        for node in paragraph:
            if node.tag == "ROFI":  # the ID we altready mapped in self.negative_id
                pass
            if node.tag == "ROFC":
                place = FZERI_NEGATIVE[self.negative_id + '/location']
                self.graph.add((place, RDF.type, CRM.E53_Place))
                self.graph.add((place, RDFS.label, Literal(node.text)))
                self.graph.add((place, CRM.P55i_is_current_location_of, negative))
                self.graph.add((negative, CRM.P55_has_current_location, place))
            if node.tag == "ROFO":
                neg_type = FZERI_PHOTOTYPE[quote_plus(node.text)]
                self.graph.add((neg_type, RDF.type, CRM.E55_Type))
                self.graph.add((neg_type, RDFS.label, Literal(node.text)))
                self.graph.add((neg_type, CRM.P2i_is_type_of, negative))
                self.graph.add((negative, CRM.P2_has_type, neg_type))
            # TODO: ROFF has yet to be mapped
            if node.tag == "ROFF":
                pass
        self.production_counter += 1
        ### end RELATIONS WITH OTHER PHOTOGRAPHIC OBJECTS (NEGATIVE) paragraph

    # begin DIGITAL IMAGE paragraph
    # example:
    #     VERSO: Pubblico
    #     FTAT: insieme
    #     FTAN: \80000\45600\45423.jpg
    #     FTAX: allegata
    #     FTAP: fotografia digitale
    def parse_paragraph_digital_image(self, paragraph, rep):
        image_id = paragraph.find('FTAN')
        if image_id is None:
            return
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        digital_image = FZERI_FENTRY[self.entry_id + '/photo/dimage/' + str(rep)]
        self.graph.add((digital_image, RDF.type, CRM.E38_Image))
        self.graph.add((digital_image, RDF.type, FABIO.DigitalManifestation))
        self.graph.add((self.myentry, FENTRY.describes, digital_image))
        self.graph.add((myphoto, FABIO.hasManifestation, digital_image))
        self.graph.add((digital_image, CRM.P138_represents, myphoto))
        self.graph.add((myphoto, CRM.P138i_has_representation, digital_image))
        img_file = FZERI_DIMAGES[image_id.text.replace('\\', '/').strip('/')]
        self.graph.add((img_file, RDF.type, CRM.E38_Image))
        self.graph.add((img_file, RDF.type, FABIO.ComputerFile))
        self.graph.add((img_file, FRBR.exemplar, digital_image))
        self.graph.add((self.myentry, FENTRY.describes, img_file))
        self.graph.add((img_file, CRM.P138_represents, digital_image))
        self.graph.add((digital_image, CRM.P138i_has_representation, img_file))
        for node in paragraph:
            if node.tag == "FTAT":
                self.graph.add((digital_image, CRM.P3_has_note, Literal(node.text)))
            elif node.tag == "FTAP":
                image_type = FZERI_PHOTOTYPE[quote_plus(node.text)]
                self.graph.add((image_type, RDF.type, CRM.E55_Type))
                self.graph.add((image_type, RDFS.label, Literal(node.text)))
                self.graph.add((image_type, CRM.P2i_is_type_of, digital_image))
                self.graph.add((digital_image, CRM.P2_has_type, image_type))
            # TODO: FTAX and VERSO
            elif node.tag == "FTAX":
                pass
            elif node.tag == "VERSO":
                pass
        ### end DIGITAL IMAGE paragraph

    # begin PROVENANCE paragraph
    # example:
    #     PRDI: 1953/12/10
    #     PRVP: Firenze
    #     PRCM: Collezione privata Gnoli Umberto
    #     PRVS: Italia
    #     PRL: Londra
    #     PRDU: 1947/ ca.
    #     PRCD: Università degli studi di Roma "La Sapienza": Dipartimento di Storia dell'Arte
    #     PRVC: Firenze
    def parse_paragraph_provenance(self, paragraph, rep):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        provenance = FZERI_FENTRY[self.entry_id + '/photo/provenance' + str(rep)]
        self.graph.add((provenance, RDF.type, CRM.E53_Place))
        self.graph.add((provenance, CRM.P53i_is_former_or_current_location_of, myphoto))
        self.graph.add((myphoto, CRM.P53_has_former_or_current_location, provenance))
        activity = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/move']
        self.graph.add((activity, RDF.type, CRM.E9_Move))
        timespan = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/move/date']
        self.graph.add((timespan, RDF.type, CRM['E52_Time-Span']))
        self.graph.add((timespan, CRM['P4i_is_time-span_of'], activity))
        self.graph.add((activity, CRM['P4_has_time-span'], timespan))
        self.graph.add((provenance, CRM.P26_moved_to, activity))
        self.graph.add((provenance, CRM.P26i_was_destination_of, activity))
        self.graph.add((activity, CRM.P25_moved, myphoto))
        self.graph.add((myphoto, CRM.P25i_moved_by, activity))
        country = district = town = repository = None
        for node in paragraph:
            if node.tag == "PRDI":
                begin = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/move/date/begin']
                self.graph.add((begin, RDF.type, TIME.Instant))
                self.graph.add((begin, TIME.inXSDDateTime, Literal(node.text)))
                self.graph.add((timespan, RDF.type, TIME.TemporalEntity))
                self.graph.add((timespan, TIME.hasBeginning, begin))
            elif node.tag == "PRDU":
                end = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/move/date/end']
                self.graph.add((end, RDF.type, TIME.Instant))
                self.graph.add((end, TIME.inXSDDateTime, Literal(node.text)))
                self.graph.add((timespan, RDF.type, TIME.TemporalEntity))
                self.graph.add((timespan, TIME.hasEnd, end))
            elif node.tag == "PRVP":
                district = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/district']
                self.graph.add((district, RDF.type, CRM.E53_Place))
                self.graph.add((district, RDFS.label, Literal(node.text)))
            elif node.tag == "PRVS":
                country = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/country']
                self.graph.add((country, RDF.type, CRM.E53_Place))
                self.graph.add((country, RDFS.label, Literal(node.text)))
            elif node.tag == "PRVC" or node.tag == "PRL":
                town = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/town']
                self.graph.add((town, RDF.type, CRM.E53_Place))
                self.graph.add((town, RDFS.label, Literal(node.text)))
            elif node.tag == "PRCM":
                collection = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/collection']
                self.graph.add((collection, RDF.type, CRM.E46_Section_Definition))
                self.graph.add((collection, RDFS.label, Literal(node.text)))
                self.graph.add((collection, CRM.P87i_identifies, provenance))
                self.graph.add((provenance, CRM.P87_is_identified_by, collection))
            elif node.tag == "PRCD":
                repository = FZERI_FENTRY[self.entry_id + '/photo/provenance/' + str(rep) + '/repository']
                self.graph.add((repository, RDF.type, CRM.E53_Place))
                self.graph.add((repository, RDFS.label, Literal(node.text)))
        contained = provenance
        for container in repository, town, district, country:
            if container:
                self.graph.add((container, CRM.P59_has_section, contained))
                self.graph.add((contained, CRM.P59i_is_located_on_or_within, container))
                contained = container
        ### end PROVENANCE paragraph

    # begin LOCATION paragraph
    # example:
    #     LDCM: Fototeca Zeri
    #     LDCN: Ex convento di S. Cristina
    #     PVCR: Emilia-Romagna
    #     PVCP: BO
    #     PVCC: Bologna
    #     LDCU: piazzetta G. Morandi, 2
    #     LDCS: Grandi Formati
    def parse_paragraph_location(self, paragraph):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        location = FZERI_FENTRY[self.entry_id + '/photo/location']
        self.graph.add((location, RDF.type, CRM.E53_Place))
        self.graph.add((location, CRM.P55i_is_current_location_of, myphoto))
        self.graph.add((myphoto, CRM.P55_has_current_location, location))
        region = district = town = repository = None
        for node in paragraph:
            if node.tag == "LDCN":
                repository = FZERI_FENTRY[self.entry_id + '/photo/location/repository']
                self.graph.add((repository, RDF.type, CRM.E53_Place))
                self.graph.add((repository, RDFS.label, Literal(node.text)))
            elif node.tag == "PVCP":
                district = FZERI_FENTRY[self.entry_id + '/photo/location/district']
                self.graph.add((district, RDF.type, CRM.E53_Place))
                self.graph.add((district, RDFS.label, Literal(node.text)))
            elif node.tag == "PVCR":
                region = FZERI_FENTRY[self.entry_id + '/photo/location/region']
                self.graph.add((region, RDF.type, CRM.E53_Place))
                self.graph.add((region, RDFS.label, Literal(node.text)))
            elif node.tag == "PVCC":
                town = FZERI_FENTRY[self.entry_id + '/photo/location/town']
                self.graph.add((town, RDF.type, CRM.E53_Place))
                self.graph.add((town, RDFS.label, Literal(node.text)))
            elif node.tag == "LDCM":
                collection = FZERI_FENTRY[self.entry_id + '/photo/location/collection']
                self.graph.add((collection, RDF.type, CRM.E46_Section_Definition))
                self.graph.add((collection, RDFS.label, Literal(node.text)))
                self.graph.add((collection, CRM.P87i_identifies, location))
                self.graph.add((location, CRM.P87_is_identified_by, collection))
            elif node.tag == "LDCS":
                precise_location = FZERI_FENTRY[self.entry_id + '/photo/location/precise_location']
                self.graph.add((precise_location, RDF.type, CRM.E46_Section_Definition))
                self.graph.add((precise_location, RDFS.label, Literal(node.text)))
                self.graph.add((precise_location, CRM.P87i_identifies, location))
                self.graph.add((location, CRM.P87_is_identified_by, precise_location))
            elif node.tag == "LDCU":
                # TODO: add VCard Ontology
                address = FZERI_FENTRY[self.entry_id + '/photo/location/address']
                self.graph.add((address, RDF.type, CRM.E53_Place))
                self.graph.add((address, RDFS.label, Literal(node.text)))
                self.graph.add((location, CRM.P87_is_identified_by, address))
        contained = location
        for container in repository, town, district, region:
            if container:
                self.graph.add((container, CRM.P59_has_section, contained))
                self.graph.add((contained, CRM.P59i_is_located_on_or_within, container))
                contained = container
        ### end LOCATION paragraph

    # begin STATE OF PRESERVATION paragraph
    # example:
    #     STCS: sbiadimento
    #     STCC: mediocre
    def parse_paragraph_state_of_preservation(self, paragraph):
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        condition = FZERI_FENTRY[self.entry_id + '/photo/condition']
        self.graph.add((condition, RDF.type, CRM.E3_Condition_State))
        self.graph.add((condition, CRM.P44i_is_condition_of, myphoto))
        self.graph.add((myphoto, CRM.P44_has_condition, condition))
        for node in paragraph:
            if node.tag == "STCS":
                self.graph.add((condition, RDFS.label, Literal(node.text)))
            elif node.tag == "STCC":
                condition_type = FZERI_CONDITIONTYPE[quote_plus(node.text)]
                self.graph.add((condition_type, RDF.type, CRM.E55_Type))
                self.graph.add((condition_type, RDFS.label, Literal(node.text)))
                self.graph.add((condition_type, CRM.P2i_is_type_of, condition))
                self.graph.add((condition, CRM.P2_has_type, condition_type))
        ### end STATE OF PRESERVATION paragraph

    # begin RELATION TO OTHER OBJECTS paragraph
    # example:
    #     OGTI: Collage di fotografie della predella raffigurante il Miracolo dell'ostia profanata di Paolo Uccello
    #     RVEL: 2
    def parse_paragraph_relation_to_other_objects(self, paragraph):
        collection_desc = paragraph.find('OGTI').text
        if collection_desc is None:
            return
        myphoto = FZERI_FENTRY[self.entry_id + '/photo']
        collection = FZERI_COLLECTION[sha1(collection_desc.encode('utf-8')).hexdigest()]
        self.graph.add((collection, RDF.type, CRM.E18_Physical_Thing))
        self.graph.add((collection, CRM.P46_is_composed_of, myphoto))
        self.graph.add((myphoto, CRM.P46i_forms_part_of, collection))
        for node in paragraph:
            # TODO
            if node.tag == "RVEL":
                pass
            elif node.tag == "OGTI":
                self.graph.add((collection, RDFS.label, Literal(node.text)))
        ### end RELATION TO OTHER OBJECTS paragraph


text:
import React from "react";
import PropTypes from "prop-types";
import styled, { keyframes, css } from "styled-components";

const loading = keyframes`
0%,
80%,
100% {
  box-shadow: 0 0;
  height: 4em;
}
40% {
  box-shadow: 0 -2em;
  height: 5em;
}
`;

const animation = props =>
  css`
    ${loading} ${props.duration}s infinite ease-in-out
  `;

const Bar = styled.div`
  animation: ${animation};
  animation-delay: ${props => `${props.duration * -0.16}s`};
  background: ${props => props.color};
  color: ${props => props.color};
  font-size: ${props => `${props.size}px`};
  height: 4em;
  margin: 88px auto;
  position: relative;
  text-indent: -9999em;
  transform: translateZ(0);
  width: 1em;

  &:before {
    animation: ${animation};
    animation-delay: ${props => `${props.duration * -0.32}s`};
    background: ${props => props.color};
    content: "";
    height: 4em;
    left: -1.5em;
    position: absolute;
    top: 0;
    width: 1em;
  }

  &:after {
    animation: ${animation};
    animation-delay: ${props => `${props.duration * 0.08}s`};
    background: ${props => props.color};
    content: "";
    height: 4em;
    left: 1.5em;
    position: absolute;
    top: 0;
    width: 1em;
  }
`;

const BarLoader = props => <Bar {...props} />;

BarLoader.propTypes = {
  color: PropTypes.string,
  duration: PropTypes.number,
  size: PropTypes.number
};

BarLoader.defaultProps = {
  color: "#3e3e3e",
  duration: 1,
  size: 11
};

export default BarLoader;

redpajama_set_name: RedPajamaGithub


text:
package com.thesis.trainingdata.features;

import java.sql.SQLException;
import java.util.Arrays;

public class DiffusionModelVector extends FeatureVector {
    public DiffusionModelVector() throws SQLException {
        Arrays.asList(
                new PostDayOfWeek(),
                new PostHourOfDay(),
                new PostLength(),
                new PostFleschReadability(),
                new AuthorId(),
                new AuthorType(),
                new AuthorReadersCount(),
                new AuthorSubscriptionsCount(),
                new AuthorsPostsWithReactionsProportion(),
                new AuthorsAge(),
                new AuthorsGender(),
                new OwnerType(),
                new OwnerReadersCount(),
                new OwnerPostsWithReactionsProportions(),
                new ReaderId(),
                new ReaderSubscriptionsCount(),
                new ReadersSubscriptionsReactedBefore(),
                new ReaderEverReactedOnAuthor(),
                new ReadersKnownReactionsBefore(),
                new ReaderEverReactedOnOwner(),
                new ReaderAuthorSocialHomogeneity(),
                new ReadersAge(),
                new ReadersGender(),
                new AuthorsSubscribersToReadersSubscribersProportion(),
                new AuthorReaderAgeDifference(),
                new AuthorReaderOfSameSex(),
                new ReaderReacted()
        ).forEach(this::addFeature);
    }
}


text:
package io.abnd.rvep.security.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.List;

/**
 * The persistent class for the auth_provider database table.
 *
 */
@Entity
@Table(name="auth_provider")
@NamedQuery(name="AuthProvider.findAll", query="SELECT a FROM AuthProvider a")
public class AuthProvider implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int id;

	private byte enabled;

	private String name;

	//bi-directional many-to-one association to RvepUserAuthProvider
	@OneToMany(mappedBy="authProvider")
	private List<RvepUserAuthProvider> rvepUserAuthProviders;

	public AuthProvider() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public byte getEnabled() {
		return this.enabled;
	}

	public void setEnabled(byte enabled) {
		this.enabled = enabled;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<RvepUserAuthProvider> getRvepUserAuthProviders() {
		return this.rvepUserAuthProviders;
	}

	public void setRvepUserAuthProviders(List<RvepUserAuthProvider> rvepUserAuthProviders) {
		this.rvepUserAuthProviders = rvepUserAuthProviders;
	}

	public RvepUserAuthProvider addRvepUserAuthProvider(RvepUserAuthProvider rvepUserAuthProvider) {
		getRvepUserAuthProviders().add(rvepUserAuthProvider);
		rvepUserAuthProvider.setAuthProvider(this);

		return rvepUserAuthProvider;
	}

	public RvepUserAuthProvider removeRvepUserAuthProvider(RvepUserAuthProvider rvepUserAuthProvider) {
		getRvepUserAuthProviders().remove(rvepUserAuthProvider);
		rvepUserAuthProvider.setAuthProvider(null);

		return rvepUserAuthProvider;
	}

}


text:
require 'sqlite3'

def get_input(prompt)
  print prompt + '>'
  return $stdin.gets.chomp
end

def get_db
  pdb = SQLite3::Database.new('/Users/rick/dev/prayerdb/.prayer.db')
  pdb.type_translation = true
  pdb.results_as_hash = true
  pdb
end

def new_prayer
  prayer_text = get_input("Prayer")
  pdb = get_db
  pdb.execute("INSERT INTO prayers (prayer, prayer_date, status)
                VALUES (?,?,'current')",
                prayer_text, Date.today.to_s)
end

def print_update_menu(menu)
  i = 1
  menu.each do |s|
    puts "#{i}: #{s.to_s.gsub('_',' ').capitalize}"
    i += 1
  end
end

def update_what(prayer)
  case prayer['status']
  when 'current'
    menu = [:mark_answered, :mark_inactive, :change_prayer, :add_tags]
  when 'inactive'
    menu = [:mark_current, :mark_answered, :add_tags]
  when 'answered'
    menu = [:change_answer, :add_tags]
  end

  print_update_menu(menu)
  option = get_input('Select option').to_i - 1
  return menu[option]
end

def update(plist, params)
  if params.empty?
    n = get_input("Prayer Number").to_i - 1
  else
    n = params[0].to_i - 1
  end

  unless (0..plist.size) === n
    puts "#{n} is not a prayer number"
    return
  end

  option = update_what(plist[n])
  pdb = get_db
  case option
  when :mark_answered
    answer = get_input('Answer')
    pdb.execute("UPDATE prayers SET status='answered', answer=?, answer_date=?
                  WHERE id=?", answer, Date.today.to_s, plist[n]['id'])
    return ['answered']
  when :mark_inactive
    pdb.execute("UPDATE prayers SET status='inactive' WHERE id=?", plist[n]['id'])
    return ['inactive']
  when :mark_current
    pdb.execute("UPDATE prayers SET status='current' WHERE id=?", plist[n]['id'])
    return []
  when :change_prayer
    prayer = get_input('New prayer')
    pdb.execute("UPDATE prayers SET prayer=? WHERE id=?", prayer, plist[n]['id'])
    return []
  when :change_answer
    answer = get_input('New answer')
    pdb.execute("UPDATE prayers SET status='answered', answer=?, answer_date=?
                  WHERE id=?", answer, Date.today.to_s, plist[n]['id'])
    return ['answered']
  when :add_tags
    tags = get_input('Tags').scan(/\w+/)
    tags.each do |tag|
      pdb.execute("INSERT INTO tags (tag, prayer_id) VALUES(?, ?)",
                    tag, plist[n]['id'])
    end
    return tags
  end
end

def make_question_marks(num)
  s = '('
  num.times{|i| s += '?,'}
  s[s.size-1] = ')'
  return s
end

def prayer_list(sql, params=[])
  pdb = get_db
  index = 1
  prayers = pdb.execute(sql, params).uniq{|p| p['id']}
  prayers.each do |prayer|
    s = "#{index}: (#{prayer['prayer_date']}) #{prayer['prayer']}"
    s += " - (#{prayer['answer_date']}) #{prayer['answer']}" if prayer['status'] == 'answered'
    puts s
    index += 1
  end
  return prayers
end

def list_with_tags(status_array, tag_array)
  sql = "SELECT * FROM prayers INNER JOIN tags ON prayers.id=tags.prayer_id WHERE "
  unless status_array.empty?
    sql += "prayers.status IN " + make_question_marks(status_array.size) + " AND "
  end
  sql += "tags.tag IN " + make_question_marks(tag_array.size)
  return prayer_list(sql, status_array + tag_array)
end

def list(params=[])
  if params.size < 1
    return prayer_list("SELECT * FROM prayers WHERE status='current'")
  else
    status_array = []
    tag_array = []
    params.each do |input|
      if ['current', 'answered', 'inactive'].include?(input)
        status_array << input
      else
        tag_array << input
      end
    end
    if tag_array.empty?
      sql = "SELECT * FROM prayers WHERE status IN " + make_question_marks(status_array.size)
      return prayer_list(sql, status_array)
    else
      return list_with_tags(status_array, tag_array)
    end
  end
end

def help
  puts "new: Add a new prayer"
  puts "update: Update an existing prayer, use the listed number"
  puts "list: list prayers. List by status of current, answered or inactive; or list by tags"
  puts "quit: self-explanatory"
end

######    script starts here     #################

plist = list()

done = false
while(!done) do
  cmd = get_input('').scan(/\w+/)
  case cmd[0].downcase
  when 'new'
    new_prayer()
    plist = list()
  when 'list'
    plist = list(cmd[1..cmd.size])
  when 'update'
    params = update(plist, cmd[1..cmd.size])
    plist = list(params)
  when 'quit'
    done = true
  else
    help()
  end
end


text:
import os
import sys

doc_path = os.path.abspath(os.path.dirname(__file__) + '/../')
sys.path.insert(0, doc_path)

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.doctest',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.viewcode',
    'sphinx.ext.githubpages',
    'sphinx_click.ext'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = 'stakkr'
copyright = '2018, Emmanuel Dyan'
author = 'Emmanuel Dyan'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '4.2'
# The full version, including alpha/beta/rc tags.
release = version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '*_stakkr']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'default'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
html_static_path = []

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
    '**': [
        'searchbox.html',
        'pages/installation.html',
        # 'navigation.rst',
        # 'cli.html',
        # 'code.html',
        # 'plugin-development.html',
        # 'donate.html',
    ]
}

# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Stakkrdoc'

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    # 'papersize': 'letterpaper',

    # The font size ('10pt', '11pt' or '12pt').
    #
    # 'pointsize': '10pt',

    # Additional stuff for the LaTeX preamble.
    #
    # 'preamble': '',

    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
    (master_doc, 'Stakkr.tex', 'Stakkr Documentation',
     'Emmanuel Dyan', 'manual'),
]

# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (master_doc, 'stakkr', 'Stakkr Documentation',
     [author], 1)
]

# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (master_doc, 'Stakkr', 'Stakkr Documentation',
     author, 'Stakkr', 'One line description of project.',
     'Miscellaneous'),
]


text:
/*
 * bpidentityparser.h
 *
 *  Created on: 18-feb-2012
 *      Author: M. El-Kebir
 */

#ifndef BPIDENTITYPARSER_H_
#define BPIDENTITYPARSER_H_

#include "input/bpparser.h"
#include "input/identityparser.h"

namespace nina {
namespace gna {

template<typename GR, typename BGR>
class BpIdentityParser : public BpParser<GR, BGR>
{
public:
  /// Graph type
  typedef GR Graph;
  /// Bipartite graph type
  typedef BGR BpGraph;
  /// Base class type
  typedef BpParser<GR, BGR> Parent;

private:
  TEMPLATE_GRAPH_TYPEDEFS(Graph);

  typedef typename Parent::BpNode BpNode;
  typedef typename Parent::BpEdge BpEdge;
  typedef typename Parent::BpArc BpArc;
  typedef typename Parent::BpNodeIt BpNodeIt;
  typedef typename Parent::BpEdgeIt BpEdgeIt;
  typedef typename Parent::BpIncEdgeIt BpIncEdgeIt;
  typedef typename Parent::BpRedNode BpRedNode;
  typedef typename Parent::BpBlueNode BpBlueNode;
  typedef typename Parent::BpRedNodeIt BpRedNodeIt;
  typedef typename Parent::BpBlueNodeIt BpBlueNodeIt;

public:
  typedef typename Parent::BpWeightEdgeMap BpWeightEdgeMap;
  typedef typename Parent::ParserType ParserType;
  typedef typename Parent::OrigNodeToMatchNodeMap OrigNodeToMatchNodeMap;
  typedef typename Parent::MatchNodeToOrigNodeMap MatchNodeToOrigNodeMap;
  typedef IdentityParser<Graph> IdentityParserType;
  typedef typename IdentityParserType::NodeRefMap NodeRefMap;
  typedef typename IdentityParserType::NodeCrossRefMap NodeCrossRefMap;
  typedef typename BpGraph::template NodeMap<BpNode> BpNodeRefMap;
  typedef typename BpGraph::template EdgeMap<BpEdge> BpEdgeRefMap;
  typedef typename BpGraph::template NodeMap<BpNode> BpNodeCrossRefMap;

  using Parent::_filename;
  using Parent::_pGm;
  using Parent::_pWeightEdgeMap;
  using Parent::_pG1ToGm;
  using Parent::_pG2ToGm;
  using Parent::_pGmToG12;
  using Parent::_nNodesRed;
  using Parent::_nNodesBlue;
  using Parent::_nEdges;
  using Parent::constructGm;

private:
  const BpGraph& _sourceGm;
  const MatchNodeToOrigNodeMap& _sourceGmToG12;
  const BpWeightEdgeMap* _pSourceWeightEdgeMap;
  const IdentityParserType* _pIdentityParserG1;
  const IdentityParserType* _pIdentityParserG2;
  BpNodeRefMap _nodeRefMap;
  BpEdgeRefMap _edgeRefMap;
  BpNodeCrossRefMap* _pNodeCrossRefMap;

public:
  BpIdentityParser(const BpGraph& sourceGm,
                   const MatchNodeToOrigNodeMap& sourceGmToG12,
                   const BpWeightEdgeMap* pSourceWeightEdgeMap,
                   const IdentityParserType* pParserG1,
                   const IdentityParserType* pParserG2);

  bool parse();

  BpEdge map(BpEdge org) const
  {
    assert(org != lemon::INVALID);
    return _edgeRefMap[org];
  }
};

template<typename GR, typename BGR>
inline BpIdentityParser<GR, BGR>::
    BpIdentityParser(const BpGraph& sourceGm,
                     const MatchNodeToOrigNodeMap& sourceGmToG12,
                     const BpWeightEdgeMap* pSourceWeightEdgeMap,
                     const IdentityParserType* pParserG1,
                     const IdentityParserType* pParserG2)
  : Parent(pParserG1, pParserG2)
  , _sourceGm(sourceGm)
  , _sourceGmToG12(sourceGmToG12)
  , _pSourceWeightEdgeMap(pSourceWeightEdgeMap)
  , _pIdentityParserG1(pParserG1)
  , _pIdentityParserG2(pParserG2)
  , _nodeRefMap(_sourceGm)
  , _edgeRefMap(_sourceGm)
  , _pNodeCrossRefMap(NULL)
{
}

template<typename GR, typename BGR>
inline bool BpIdentityParser<GR, BGR>::parse()
{
  if (!_pGm || !_pG1ToGm || !_pG2ToGm || !_pGmToG12)
    return false;

  _pGm->clear();

  lemon::BpGraphCopy<BpGraph, BpGraph> copy(_sourceGm, *_pGm);
  copy.nodeRef(_nodeRefMap);
  copy.edgeRef(_edgeRefMap);

  delete _pNodeCrossRefMap;
  _pNodeCrossRefMap = new BpNodeCrossRefMap(*_pGm);
  copy.nodeCrossRef(*_pNodeCrossRefMap);

  if (_pSourceWeightEdgeMap && _pWeightEdgeMap)
  {
    copy.edgeMap(*_pSourceWeightEdgeMap, *_pWeightEdgeMap);
  }

  copy.run();

  _nNodesRed = 0;
  const NodeRefMap& nodeRefG1 = _pIdentityParserG1->getNodeRefMap();
  for (BpRedNodeIt sourceBpNode(_sourceGm);
       sourceBpNode != lemon::INVALID; ++sourceBpNode)
  {
    BpNode targetBpNode = _nodeRefMap[sourceBpNode];

    Node sourceNode = _sourceGmToG12[sourceBpNode];
    Node targetNode = nodeRefG1[sourceNode];

    _pG1ToGm->set(targetNode, targetBpNode);
    _pGmToG12->set(targetBpNode, targetNode);

    _nNodesRed++;
  }

  _nNodesBlue = 0;
  const NodeRefMap& nodeRefG2 = _pIdentityParserG2->getNodeRefMap();
  for (BpBlueNodeIt sourceBpNode(_sourceGm);
       sourceBpNode != lemon::INVALID; ++sourceBpNode)
  {
    BpNode targetBpNode = _nodeRefMap[sourceBpNode];

    Node sourceNode = _sourceGmToG12[sourceBpNode];
    Node targetNode = nodeRefG2[sourceNode];

    _pG2ToGm->set(targetNode, targetBpNode);
    _pGmToG12->set(targetBpNode, targetNode);

    _nNodesBlue++;
  }

  _nEdges = 0;
  for (BpEdgeIt e(_sourceGm); e != lemon::INVALID; ++e)
    _nEdges++;

  return true;
}

} // namespace gna
} // namespace nina

#endif // BPIDENTITYPARSER_H_


text:
#include "ultraviolet.h"

using namespace iotik::blocks::details;

UltravioletSensorBlock::UltravioletSensorBlock()
{
}

void UltravioletSensorBlock::run()
{
	//evalCode(stringProperty("Variable") + " = ultraviolet[0]");
	emit done(mNextBlockId);
}


text:
using System.IO.Abstractions;

namespace PassWinmenu.PasswordManagement
{
	/// <summary>
	/// Represents a decrypted password file of an unknown format.
	/// </summary>
	internal class DecryptedPasswordFile : PasswordFile
	{
		// Allow derived types to set the content.
		public string Content { get; protected set; }

		public DecryptedPasswordFile(PasswordFile original, string content) : base(original)
		{
			Content = content;
		}

		// Only derived types may call this constructor, since they may want to determine the content themselves.
		protected DecryptedPasswordFile(PasswordFile original) : base(original)
		{
		}
	}
}


text:
package com.vipshop.microscope.common.aop;

/**
 * @author Xu Fei
 * @version 1.0
 */
public class Checker {

    public static void check() {
        System.out.println("check operation");
    }
}


text:
#include "config.h"

#if USE(ACCELERATED_COMPOSITING)

#include "ImageLayerChromium.h"

#include "cc/CCLayerImpl.h"
#include "Image.h"
#include "LayerRendererChromium.h"
#include "LayerTexture.h"

namespace WebCore {

PassRefPtr<ImageLayerChromium> ImageLayerChromium::create(GraphicsLayerChromium* owner)
{
    return adoptRef(new ImageLayerChromium(owner));
}

ImageLayerChromium::ImageLayerChromium(GraphicsLayerChromium* owner)
    : ContentLayerChromium(owner)
    , m_imageForCurrentFrame(0)
    , m_contents(0)
{
}

void ImageLayerChromium::setContents(Image* contents)
{
    // setContents() currently gets called whenever there is any
    // style change that affects the layer even if that change doesn't
    // affect the actual contents of the image (e.g. a CSS animation).
    // With this check in place we avoid unecessary texture uploads.
    if ((m_contents == contents) && (m_contents->nativeImageForCurrentFrame() == m_imageForCurrentFrame))
        return;

    m_contents = contents;
    m_imageForCurrentFrame = m_contents->nativeImageForCurrentFrame();
    m_dirtyRect = IntRect(IntPoint(0, 0), bounds());
    setNeedsDisplay();
}

void ImageLayerChromium::paintContentsIfDirty(const IntRect&)
{
    ASSERT(layerRenderer());

    if (!m_dirtyRect.isEmpty()) {
        m_decodedImage.updateFromImage(m_contents->nativeImageForCurrentFrame());
        updateLayerSize(m_decodedImage.size());
        IntRect paintRect(IntPoint(0, 0), m_decodedImage.size());
        if (!m_dirtyRect.isEmpty()) {
            m_tiler->invalidateRect(paintRect);
            m_dirtyRect = IntRect();
        }
    }
}

void ImageLayerChromium::updateCompositorResources()
{
    IntRect paintRect(IntPoint(0, 0), m_decodedImage.size());
    m_tiler->updateFromPixels(paintRect, paintRect, m_decodedImage.pixels());
}

IntRect ImageLayerChromium::layerBounds() const
{
    return IntRect(IntPoint(0, 0), m_decodedImage.size());
}

TransformationMatrix ImageLayerChromium::tilingTransform()
{
    // Tiler draws from the upper left corner. The draw transform
    // specifies the middle of the layer.
    TransformationMatrix transform = ccLayerImpl()->drawTransform();
    const IntRect sourceRect = layerBounds();
    const IntSize destSize = bounds();

    transform.translate(-destSize.width() / 2.0, -destSize.height() / 2.0);

    // Tiler also draws at the original content size, so rescale the original
    // image dimensions to the bounds that it is meant to be drawn at.
    float scaleX = destSize.width() / static_cast<float>(sourceRect.size().width());
    float scaleY = destSize.height() / static_cast<float>(sourceRect.size().height());
    transform.scale3d(scaleX, scaleY, 1.0f);

    return transform;
}

}
#endif // USE(ACCELERATED_COMPOSITING)


text:
from datetime import datetime
from django.http import HttpResponse, HttpResponseBadRequest
from custom.apps.wisepill.models import WisePillDeviceEvent
from corehq.apps.sms.handlers.keyword import handle_structured_sms
from corehq.apps.sms.models import CommConnectCase
from corehq.apps.reminders.models import SurveyKeyword, METHOD_STRUCTURED_SMS
from corehq.apps.api.models import require_api_user_permission, PERMISSION_POST_WISEPILL

@require_api_user_permission(PERMISSION_POST_WISEPILL)
def device_data(request):
    if "data" not in request.POST:
        return HttpResponseBadRequest("Missing 'data' POST parameter.")

    data = request.POST.get("data")
    data = data.strip()
    data_points = data.split(",")
    device_id = None
    for data_point in data_points:
        key_value = data_point.partition("=")
        key = key_value[0].strip().upper()
        value = key_value[2].strip()
        if key == "SN":
            device_id = value
            break

    if device_id is None:
        return HttpResponseBadRequest("Missing 'SN' in data string.")

    # This view lookup is an implicit assert that either one device exists
    # with the given device_id, or no devices exist with this device_id.
    case = CommConnectCase.view("wisepill/device",
                                key=[device_id],
                                include_docs=True).one()

    event = WisePillDeviceEvent(
        domain=case.domain if case is not None else None,
        data=data,
        received_on=datetime.utcnow(),
        case_id=case._id if case is not None else None,
        processed=False,
    )
    event.save()

    if case is not None:
        survey_keywords = SurveyKeyword.get_all(case.domain)
        for survey_keyword in survey_keywords:
            if survey_keyword.keyword.upper() == "DEVICE_EVENT":
                for survey_keyword_action in survey_keyword.actions:
                    if survey_keyword_action.action == METHOD_STRUCTURED_SMS:
                        handle_structured_sms(survey_keyword, survey_keyword_action, case, None, "DEVICE_EVENT,%s" % data, send_response=False)
                        event.processed = True
                        event.save()
                        break

    return HttpResponse("")


text:
import dbus
from sys import path

from module import PtyshModule

HOSTNAME_SERVICE_NAME = "org.freedesktop.hostname1"
HOSTNAME_OBJECT_PATH = "/org/freedesktop/hostname1"
HOSTNAME_INTERFACE = "org.freedesktop.hostname1"

DBUS_BUS_NAME = "com.kssim.test"
DBUS_OBJECT_PATH = "/com/kssim/test"

class test_module(PtyshModule):

    welcome_msg = "empty"

    def __init__(self):
        super(test_module, self).__init__()
        super(test_module, self).init_node("hello", "hello node")

        super(test_module, self).add_command("show hello", "show hello", self.cmd_show_hello_hidden, "hidden command", False)

        super(test_module, self).add_command("welcome_msg set", "set welcome message", self.cmd_welcome_set_msg, "welcome_msg set [message]")
        super(test_module, self).add_command("show welcome_msg", "show welcome message", self.cmd_show_welcome_msg)

        super(test_module, self).add_command("show hostname property", "show hostname properties", self.cmd_show_hostname_property)
        super(test_module, self).add_command("show hostname", "show hostname", self.cmd_show_hostname)
        super(test_module, self).add_command("hostname set", "set hostname", self.cmd_hostname_set, "hostname set [hostname]")
        super(test_module, self).add_command("show machine id", "show machine id", self.cmd_show_machine_id)
        super(test_module, self).add_command("show introspect", "show introspect", self.cmd_show_introspect, "", False)

        # get "hostname" dbus interface.
        self.hostname_dbus = super(test_module, self).get_dbus(HOSTNAME_SERVICE_NAME, HOSTNAME_OBJECT_PATH)

    def cmd_show_welcome_msg(self):
        # basic command
        print (self.welcome_msg)

    def cmd_show_hello_hidden(self):
        # hidden command
        print ("hello world")

    def cmd_welcome_set_msg(self, args):
        # basic set command
        if len(args) != 1:
            raise TypeError

        self.welcome_msg = args[0]

    def cmd_show_hostname_property(self):
        # property for get all.
        result = self.hostname_dbus.dbus_get_property(HOSTNAME_INTERFACE)

        for k,v in result.items():
            print ("%s : %s" % (k, v))

    def cmd_show_hostname(self):
        # property for get one item.
        result = self.hostname_dbus.dbus_get_property(HOSTNAME_INTERFACE, "StaticHostname")
        print (str(result))

    def cmd_hostname_set(self, args):
        # method call for SET.
        if len(args) != 1:
            raise TypeError

        result = self.hostname_dbus.dbus_method_call("SetStaticHostname", "org.freedesktop.hostname1", args[0], True)
        print (str(result))

    def cmd_show_machine_id(self):
        # method call for GET.
        result = self.hostname_dbus.dbus_method_call("GetMachineId", dbus.PEER_IFACE)
        print (str(result))

    def cmd_show_introspect(self):
        # Introspect
        result = self.hostname_dbus.dbus_introspect()
        print (str(result))


text:
{- |
module: Main
description: Decode a UTF-8 byte stream on standard input
license: MIT

maintainer: Joe Leslie-Hurd <joe@gilith.com>
stability: provisional
portability: portable
-}
module Main
  ( main )
where

import qualified Data.Word as Word

import OpenTheory.Unicode
import qualified Unicode

info :: Either Word.Word8 Unicode -> String
info (Left b) = "invalid byte " ++ show b
info (Right c) =
    "valid unicode character " ++ show (unUnicode c) ++ " " ++
    Unicode.toString c

display :: Either Word.Word8 Unicode -> IO ()
display c = putStrLn (info c)

main :: IO ()
main =
    do cs <- Unicode.decode
       mapM_ display cs


text:
(function() {
  "use strict";

  /**
   * Take an UploadTask and create an interface for the user to monitor the
   * file's upload. The $progress, $error, and $complete methods are provided
   * to work with the $digest cycle.
   *
   * @param task
   * @param $firebaseUtils
   * @returns A converted task, which contains methods for monitoring the
   * upload progress.
   */
  function _convertTask(task, $firebaseUtils) {
    return {
      $progress: function $progress(callback) {
        task.on('state_changed', function () {
          $firebaseUtils.compile(function () {
            callback(_unwrapStorageSnapshot(task.snapshot));
          });
        });
      },
      $error: function $error(callback) {
        task.on('state_changed', null, function (err) {
          $firebaseUtils.compile(function () {
            callback(err);
          });
        });
      },
      $complete: function $complete(callback) {
        task.on('state_changed', null, null, function () {
          $firebaseUtils.compile(function () {
            callback(_unwrapStorageSnapshot(task.snapshot));
          });
        });
      },
      $cancel: task.cancel,
      $resume: task.resume,
      $pause: task.pause,
      then: task.then,
      catch: task.catch,
      $snapshot: task.snapshot
    };
  }

  /**
   * Take a Storage snapshot and unwrap only the needed properties.
   *
   * @param snapshot
   * @returns An object containing the unwrapped values.
   */
  function _unwrapStorageSnapshot(storageSnapshot) {
    return {
      bytesTransferred: storageSnapshot.bytesTransferred,
      downloadURL: storageSnapshot.downloadURL,
      metadata: storageSnapshot.metadata,
      ref: storageSnapshot.ref,
      state: storageSnapshot.state,
      task: storageSnapshot.task,
      totalBytes: storageSnapshot.totalBytes
    };
  }

  /**
   * Determines if the value passed in is a Storage Reference. The
   * put method is used for the check.
   *
   * @param value
   * @returns A boolean that indicates if the value is a Storage Reference.
   */
  function _isStorageRef(value) {
    value = value || {};
    return typeof value.put === 'function';
  }

  /**
   * Checks if the parameter is a Storage Reference, and throws an
   * error if it is not.
   *
   * @param storageRef
   */
  function _assertStorageRef(storageRef) {
    if (!_isStorageRef(storageRef)) {
      throw new Error('$firebaseStorage expects a Storage reference');
    }
  }

  /**
   * This constructor should probably never be called manually. It is setup
   * for dependecy injection of the $firebaseUtils and $q service.
   *
   * @param {Object} $firebaseUtils
   * @param {Object} $q
   * @returns {Object}
   * @constructor
   */
  function FirebaseStorage($firebaseUtils, $q) {

    /**
     * This inner constructor `Storage` allows for exporting of private methods
     * like _assertStorageRef, _isStorageRef, _convertTask, and _unwrapStorageSnapshot.
     */
    var Storage = function Storage(storageRef) {
      _assertStorageRef(storageRef);
      return {
        $put: function $put(file, metadata) {
          var task = storageRef.put(file, metadata);
          return _convertTask(task, $firebaseUtils);
        },
        $putString: function $putString(data, format, metadata) {
          var task = storageRef.putString(data, format, metadata);
          return _convertTask(task, $firebaseUtils);
        },
        $getDownloadURL: function $getDownloadURL() {
          return $q.when(storageRef.getDownloadURL());
        },
        $delete: function $delete() {
          return $q.when(storageRef.delete());
        },
        $getMetadata: function $getMetadata() {
          return $q.when(storageRef.getMetadata());
        },
        $updateMetadata: function $updateMetadata(object) {
          return $q.when(storageRef.updateMetadata(object));
        },
        $toString: function $toString() {
          return storageRef.toString();
        }
      };
    };

    Storage.utils = {
      _unwrapStorageSnapshot: _unwrapStorageSnapshot,
      _isStorageRef: _isStorageRef,
      _assertStorageRef: _assertStorageRef
    };

    return Storage;
  }

  /**
   * Creates a wrapper for the firebase.storage() object. This factory allows
   * you to upload files and monitor their progress and the callbacks are
   * wrapped in the $digest cycle.
   */
  angular.module('firebase.storage')
    .factory('$firebaseStorage', ["$firebaseUtils", "$q", FirebaseStorage]);

})();


text:
import {Component} from '@angular/core';
@Component({
  selector: 'app-root',
  template: `
        Home
        Product Details
        <router-outlet></router-outlet>
    `
})
export class AppComponent {}

/*
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app works!';
}
*/


text:
from __future__ import unicode_literals

import datetime
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Node',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=50, verbose_name='\u8282\u70b9\u540d\u79f0')),
                ('add_time', models.DateField(default=datetime.datetime.now, verbose_name='\u6dfb\u52a0\u65f6\u95f4')),
            ],
            options={
                'verbose_name': '\u8bba\u575b\u8282\u70b9',
                'verbose_name_plural': '\u8bba\u575b\u8282\u70b9',
            },
        ),
        migrations.CreateModel(
            name='Reply',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('content', models.TextField(verbose_name='\u5185\u5bb9')),
                ('add_time', models.DateField(default=datetime.datetime.now, verbose_name='\u6dfb\u52a0\u65f6\u95f4')),
                ('modify_time', models.DateField(verbose_name='\u4fee\u6539\u65f6\u95f4')),
                ('seq_num', models.IntegerField(verbose_name='\u5e8f\u53f7')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='\u521b\u5efa\u8005')),
            ],
            options={
                'verbose_name': '\u4e3b\u9898\u56de\u590d',
                'verbose_name_plural': '\u4e3b\u9898\u56de\u590d',
            },
        ),
        migrations.CreateModel(
            name='Topic',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=100, verbose_name='\u6807\u9898')),
                ('content', models.TextField(verbose_name='\u5185\u5bb9')),
                ('add_time', models.DateField(default=datetime.datetime.now, verbose_name='\u6dfb\u52a0\u65f6\u95f4')),
                ('modify_time', models.DateField(verbose_name='\u4fee\u6539\u65f6\u95f4')),
                ('click_nums', models.IntegerField(default=0, verbose_name='\u70b9\u51fb\u6570')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='\u521b\u5efa\u8005')),
            ],
            options={
                'verbose_name': '\u4e3b\u9898',
                'verbose_name_plural': '\u4e3b\u9898',
            },
        ),
        migrations.AddField(
            model_name='reply',
            name='topic',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='forum.Topic', verbose_name='\u6240\u5c5e\u4e3b\u9898'),
        ),
    ]


text:
<resources>
    <string name="app_name">EmailLoginSample</string>
</resources>


text:
package route_53

import . "github.com/jagregory/cfval/schema"

// see: http://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets_Requests.html#change-rrsets-request-continent-code
var continentCode = EnumValue{
	Description: "GeoLocation Continent Code",

	Options: []string{"AF", "AN", "AS", "EU", "OC", "NA", "SA"},
}