class PersonnelAgent(Parser): schema = tools.GuessAgentType( tools.RunPython('combine_first_last_name', ctx)) name = tools.RunPython('combine_first_last_name', ctx) location = tools.RunPython('get_address', ctx['Contact_Address']) class Extra: role = tools.Try(ctx.Role) url = tools.Try(ctx.Data_Center_URL) def combine_first_last_name(self, ctx): return ctx['First_Name'] + ' ' + ctx['Last_Name'] def get_address(self, ctx): address = ctx['Address'] if isinstance(address, list): address1 = address[0] address2 = address[1] return format_address(address1=address1, address2=address2, city=ctx['City'], state_or_province=ctx['Province_or_State'], postal_code=ctx['Postal_Code'], country=ctx['Country']) return format_address(address1=ctx['Address'], address2=address2, city=ctx['City'], state_or_province=ctx['Province_or_State'], postal_code=ctx['Postal_Code'], country=ctx['Country'])
class FunderAgent(Parser): schema = tools.GuessAgentType(tools.OneOf(ctx.funderName, ctx.contributorName), default='organization') name = tools.OneOf(ctx.funderName, ctx.contributorName) identifiers = tools.Map( tools.Delegate(AgentIdentifier), tools.Try(tools.IRI( tools.OneOf(ctx.funderIdentifier, tools.RunPython(force_text, ctx.nameIdentifier), tools.Static(None))), exceptions=(ValueError, ))) class Extra: name_identifier = tools.Try(ctx.nameIdentifier) name_identifier_scheme = tools.Try( ctx.nameIdentifier['@nameIdentifierScheme']) name_identifier_scheme_uri = tools.Try( ctx.nameIdentifier['@schemeURI']) funder_identifier = tools.Try(ctx.funderIdentifier) funder_identifier_type = tools.Try(ctx.funderIdentifierType) contributor_type = tools.Try(ctx.contributorType)
class FundingAgent(Parser): schema = tools.GuessAgentType(ctx.sponsorName, default='organization') name = ctx.sponsorName identifiers = tools.Map(tools.Delegate(AgentIdentifier), tools.IRI(tools.Try(ctx.sponsorIdentifier)))
class DataCenterAgent(Parser): schema = tools.GuessAgentType(ctx.Data_Center_Name.Long_Name, default='organization') name = ctx.Data_Center_Name.Long_Name related_agents = tools.Map(tools.Delegate(IsAffiliatedWith), tools.Try(ctx.Personnel)) class Extra: data_center_short_name = ctx.Data_Center_Name.Short_Name
class AffiliatedAgent(Parser): schema = tools.GuessAgentType(ctx.awardeeName, default='organization') name = ctx.awardeeName location = tools.Join(tools.Concat(ctx.awardeeCity, tools.Try(ctx.awardeeStateCode)), joiner=', ') class Extra: awardee_city = ctx.awardeeCity awardee_state_code = tools.Try(ctx.awardeeStateCode)
class Organization(Parser): schema = tools.GuessAgentType(ctx) name = tools.RunPython('get_name', ctx) location = tools.RunPython('get_location', ctx) def get_name(self, context): return context.split(',')[0] def get_location(self, context): spl = context.partition(',') if len(spl) > 1: return spl[-1] return None
class ContributorAgent(Parser): schema = tools.OneOf( tools.GuessAgentType(tools.RunPython(get_agent_type, ctx, person=False), default='organization'), tools.GuessAgentType(tools.OneOf(ctx.creatorName, ctx.contributorName))) name = tools.OneOf(ctx.creatorName, ctx.contributorName) identifiers = tools.Map( tools.Delegate(AgentIdentifier), tools.Try(tools.IRI(tools.RunPython(force_text, ctx.nameIdentifier)), exceptions=(ValueError, ))) related_agents = tools.Map( tools.Delegate(IsAffiliatedWith), tools.Concat( tools.Try( tools.Filter(lambda x: bool(x), tools.RunPython(force_text, ctx.affiliation))))) class Extra: name_identifier = tools.Try(ctx.nameIdentifier) name_identifier_scheme = tools.Try( ctx.nameIdentifier['@nameIdentifierScheme']) name_identifier_scheme_uri = tools.Try( ctx.nameIdentifier['@schemeURI']) contributor_type = tools.Try(ctx.contributorType) # v.4 new givenName and familyName properties given_name = tools.OneOf(ctx.creatorName['@givenName'], ctx.contributorName['@givenName'], tools.Static(None)) family_name = tools.OneOf(ctx.creatorName['@familyName'], ctx.contributorName['@familyName'], tools.Static(None))
class Agent(Parser): schema = tools.GuessAgentType(ctx.name) name = ctx.name related_agents = tools.Map(tools.Delegate(IsAffiliatedWith), tools.Try(ctx.affiliation)) identifiers = tools.Map( tools.Delegate(AgentIdentifier), tools.Map(tools.IRI(), tools.Try(ctx.sameAs), tools.Try(ctx.email))) class Extra: givenName = tools.Try(ctx.givenName) familyName = tools.Try(ctx.familyName) additonalName = tools.Try(ctx.additionalName) name = tools.Try(ctx.name)
class OAIPublisher(Parser): schema = 'Publisher' agent = tools.Delegate( OAIAgent.using( schema=tools.GuessAgentType(ctx, default='organization')), ctx)
class OAIAgent(Parser): schema = tools.GuessAgentType(ctx) name = ctx
class FunderAgent(Parser): schema = tools.GuessAgentType(ctx.agency, default='organization') name = ctx.agency
class Organization(Parser): schema = tools.GuessAgentType(ctx, default='Organization') name = ctx
class PublisherAgent(Parser): schema = tools.GuessAgentType(ctx, default='organization') name = ctx
class AffiliatedAgent(Parser): schema = tools.GuessAgentType(ctx, default='organization') name = ctx
class OrgAgent(Agent): schema = tools.GuessAgentType(ctx.name, default='organization')