def get_PA(): pas = cf.find_all("POLITICALAFFILIATION") for x in pas: value = utilities.get_reg(x) orgName = get_org(x) if not value and orgName: for org in orgName: cf_list.append( CulturalForm(None, None, get_org_uri(org), other_attributes=utilities.NS_DICT["org"]. memberOf)) value = get_org_uri(org) elif orgName: for org in orgName: cf_list.append( CulturalForm(None, None, get_org_uri(org), other_attributes=utilities.NS_DICT["org"]. memberOf)) value = get_mapped_term("PoliticalAffiliation", utilities.get_value(x), id=person.id) else: value = get_mapped_term("PoliticalAffiliation", utilities.get_value(x), id=person.id) gender_issue = False if x.get("WOMAN-GENDERISSUE") == "GENDERYES": cf_list.append( CulturalForm("hasGenderedPoliticalActivity", get_reported(x), value)) gender_issue = True if x.get("ACTIVISM") == "ACTIVISTYES": cf_list.append( CulturalForm("hasActivistInvolvementIn", None, value)) elif x.get("MEMBERSHIP") == "MEMBERSHIPYES": cf_list.append( CulturalForm("hasPoliticalMembershipIn", None, value)) elif x.get("INVOLVEMENT") == "INVOLVEMENTYES": cf_list.append( CulturalForm("hasPoliticalInvolvementIn", None, value)) else: if not gender_issue: cf_list.append( CulturalForm("hasPoliticalAffiliation", get_reported(x), value))
def get_other_cfs(): tags = { "NATIONALITY": ["hasNationality", "NationalIdentity"], "SEXUALIDENTITY": ["hasSexuality", "Sexuality"] } for tag in tags.keys(): instances = cf.find_all(tag) for x in instances: value = utilities.get_value(x) if tags[tag][1] == "NationalIdentity": if value == "Indian/English": cf_list.append( CulturalForm( tags[tag][0], get_reported(x), get_mapped_term(tags[tag][1], value.split("/")[0], id=person.id))) value = value.split("/")[1] elif value == "Scots-American": cf_list.append( CulturalForm( tags[tag][0], get_reported(x), get_mapped_term(tags[tag][1], value.split("-")[0], id=person.id))) value = value.split("-")[1] value = get_mapped_term(tags[tag][1], value, id=person.id) cf_list.append( CulturalForm(tags[tag][0], get_reported(x), value)) if tags[tag][1] == "NationalIdentity": person.nationalities.append(str(value))
def get_denomination(): religions = cf.find_all("DENOMINATION") for x in religions: value = utilities.get_reg(x) orgName = get_org(x) if not value and orgName: for org in orgName: cf_list.append( CulturalForm(None, None, get_org_uri(org), other_attributes=utilities.NS_DICT["org"]. memberOf)) elif orgName: for org in orgName: cf_list.append( CulturalForm(None, None, get_org_uri(org), other_attributes=utilities.NS_DICT["org"]. memberOf)) value = get_mapped_term("Religion", utilities.get_value(x), True, id=person.id) # Checking if religion occurs as a PA if no result as a religion if type(value) is Literal: value = get_mapped_term("PoliticalAffiliation", utilities.get_value(x), True, id=person.id) # logger.warning("Mapping Religion to PA: " + value) if type(value) is Literal: value = get_mapped_term("Religion", utilities.get_value(x), id=person.id) religion = CulturalForm("hasReligion", get_reported(x), value) cf_list.append(religion)
def get_class(): classes = cf.find_all("CLASS") for x in classes: value = x.get("SOCIALRANK") if not value or value == "OTHER": value = utilities.get_value(x) cf_list.append( CulturalForm("hasSocialClass", get_reported(x), get_mapped_term("SocialClass", value)))
def get_actors(tag): """ Returns actors within an event (any name/org/title mentioned)""" actors = [] for x in tag.find_all("NAME"): actors.append(utilities.make_standard_uri(x.get("STANDARD"))) for x in tag.find_all("ORGNAME"): actors.append(organizations.get_org_uri(x)) for x in tag.find_all("TITLE"): title = utilities.get_value(x) actors.append(utilities.make_standard_uri(title + " TITLE", ns="cwrc")) return actors
def get_geoheritage(tag): places = tag.find_all("PLACE") if places: place_values = [] for x in places: temp_place = Place(x) if type(temp_place.uri) is Literal: value = get_mapped_term("GeographicHeritage", temp_place.address, id=person.id) place_values.append(value) else: place_values.append(temp_place.uri) return place_values else: return get_mapped_term("GeographicHeritage", utilities.get_value(tag), id=person.id)
def get_language(): langs = cf.find_all("LANGUAGE") for x in langs: value = utilities.get_value(x) # What if nested ethnicity tag? competence = x.get("COMPETENCE") predicate = "" if competence == "MOTHER": predicate = "hasNativeLinguisticAbility" elif competence == "OTHER": predicate = "hasLinguisticAbility" else: predicate = "hasLinguisticAbility" if value == "hindustani": cf_list.append( CulturalForm(predicate, None, get_mapped_term("Language", "hindi"))) cf_list.append( CulturalForm(predicate, None, get_mapped_term("Language", value)))
def get_forebear_cfs(): # NOTE: This will have to interact will sparql endpoint to check family related triples # sparql query to check if person hasMother/hasFather, and there is a valid uri # otherwise create the person and familial relation? def get_forebear(tag): return utilities.get_attribute(tag, "FOREBEAR") # This optional attribute attaches to the elements Ethnicity, Geographical Heritage, National Heritage, or Race, Colour, # has ten possible values: Father, Mother, Parents, Grandfather, Grandmother, Grandparents, Aunt, Uncle, Other, and Family. # We can only make assumptions about the father, mother, parents, will have to create random relative's otherwise def existing_forebear(relation): # TODO: sparql query to check if relation exists will also need person's uri # also check current uber graph? return None def add_forebear(relation, culturalform): family = { "FATHER": "hasFather", "MOTHER": "hasMother", "GRANDFATHER": "hasGrandFather", "GRANDMOTHER": "hasGrandMother", "AUNT": "hasAunt", "UNCLE": "hasUncle" } # check graph for existing forebear and get their uri forebear_uri = existing_forebear(family[relation]) if not forebear_uri: pass # create forebear # check if uri available # foafname # type as real person # gender # person_uri cwrc.relation forebear_uri # uber_graph.add() # forebear_uri culturalform.predicate culturalform.value # Create pass tags = { "RACECOLOUR": "RaceColour", "NATIONALHERITAGE": "NationalHeritage", "GEOGHERITAGE": "GeographicHeritage", "ETHNICITY": "Ethnicity" } for tag in tags.keys(): instances = cf.find_all(tag) for x in instances: culturalforms = [] forebear = get_forebear(x) if tag == "GEOGHERITAGE": value = get_geoheritage(x) if type(value) is list: for place in value: culturalforms.append( CulturalForm("has" + tags[tag], get_reported(x), place)) else: culturalforms.append( CulturalForm("has" + tags[tag], get_reported(x), value)) else: value = utilities.get_value(x) if tag == "NATIONALHERITAGE" and value in [ "American-Austrian", "Anglo-Scottish", "Scottish-Irish" ]: culturalforms.append( CulturalForm( "has" + tags[tag], get_reported(x), get_mapped_term(tags[tag], value.split("-")[0], id=person.id))) culturalforms.append( CulturalForm( "has" + tags[tag], get_reported(x), get_mapped_term(tags[tag], value.split("-")[1], id=person.id))) else: culturalforms.append( CulturalForm( "has" + tags[tag], get_reported(x), get_mapped_term(tags[tag], value, id=person.id))) for culturalform in culturalforms: cf_list.append(culturalform) if not forebear or forebear in ["OTHER", "FAMILY"]: continue if forebear == "PARENTS": add_forebear("MOTHER", culturalform) add_forebear("FATHER", culturalform)