示例#1
0
def create_geo_coordinate_from(content: str,
                               **kwargs) -> wdi_core.WDGlobeCoordinate:
    """ Create a WDGlobecoordinate object from the point representation in a str. """
    latitude, longitude = content[5:].strip('()').split(" ")
    precision = max(latitude[::-1].find('.'), longitude[::-1].find('.'))
    return wdi_core.WDGlobeCoordinate(float(latitude), float(longitude),
                                      precision, **kwargs)
示例#2
0
def test_geocoordinates_mapping():
    result = datatype2wdiobject[f"{GEO_BASE}wktLiteral"]("Point(36.834 2.463)",
                                                         prop_nr=-1)
    expected = wdi_core.WDGlobeCoordinate(latitude=36.834,
                                          longitude=2.463,
                                          precision=3,
                                          prop_nr=-1)
    assert result == expected
示例#3
0
    def test_new_item_creation(self):
        data = [
            wdi_core.WDString(value='test', prop_nr='P1'),
            wdi_core.WDString(value='test1', prop_nr='P2'),
            wdi_core.WDMath("xxx", prop_nr="P3"),
            wdi_core.WDExternalID("xxx", prop_nr="P4"),
            wdi_core.WDItemID("Q123", prop_nr="P5"),
            wdi_core.WDTime('+%Y-%m-%dT%H:%M:%SZ', "P6"),
            wdi_core.WDUrl("http://www.google.com", "P7"),
            wdi_core.WDMonolingualText("xxx", prop_nr="P8"),
            wdi_core.WDQuantity(5, prop_nr="P9"),
            wdi_core.WDQuantity(5, upper_bound=9, lower_bound=2,
                                prop_nr="P10"),
            wdi_core.WDCommonsMedia("xxx", prop_nr="P11"),
            wdi_core.WDGlobeCoordinate(1.2345, 1.2345, 12, prop_nr="P12"),
            wdi_core.WDGeoShape("xxx", prop_nr="P13"),
            wdi_core.WDProperty("P123", "P14")
        ]
        core_props = set(["P{}".format(x) for x in range(20)])

        for d in data:
            item = wdi_core.WDItemEngine(item_name='dae',
                                         domain="szadf",
                                         data=[d],
                                         core_props=core_props)
            assert item.get_wd_json_representation()
            item = wdi_core.WDItemEngine(item_name='dae',
                                         domain="szadf",
                                         data=[d],
                                         core_props=set())
            assert item.get_wd_json_representation()

        item = wdi_core.WDItemEngine(item_name='dae',
                                     domain="szadf",
                                     data=data,
                                     core_props=core_props)
        assert item.get_wd_json_representation()
        item = wdi_core.WDItemEngine(item_name='dae',
                                     domain="szadf",
                                     data=data,
                                     core_props=set())
        assert item.get_wd_json_representation()
                description="License"),
                              prop_nr="P5"))
        data.append(
            wdi_core.WDUrl(observations[observation]["url"], prop_nr="P6"))
        for image_url in observations[observation]["image_url"]:
            try:
                data.append(
                    wdi_core.WDUrl(image_url.split("?")[0].replace(
                        "medium", "original"),
                                   prop_nr="P7"))
            except:
                pass
        data.append(
            wdi_core.WDGlobeCoordinate(
                latitude=observations[observation]["latitude"],
                longitude=observations[observation]["longitude"],
                precision=0.016666666666667,
                prop_nr="P8"))
        data.append(
            wdi_core.WDItemID(value=get_or_createItem(
                observations[observation]["scientific_name"],
                description="Scientific taxon name"),
                              prop_nr="P9"))
        # data.append(wdiobservations[observation]["taxon_id"], prop_nr="P10")

        item = wikibaseEntityEngine(data=data)
        item.set_label("iNaturalist observation " + observation, lang="en")
        item.set_description("Observation of " +
                             observations[observation]["scientific_name"],
                             lang="en")
        # pprint.pprint(item.get_wd_json_representation())
示例#5
0
def create_grid_item(grid_data, grid_id, grid_release_item_id, login_instance):
    reference_info = [
        wdi_core.WDItemID(grid_release_item_id, 'P248', is_reference=True),
        wdi_core.WDExternalID(grid_id, p_grid_id, is_reference=True)
    ]
    base_data = grid_data.base_data_for_id(grid_id)
    org_name = base_data['label']
    org_description = base_data['description']
    org_type_qid = base_data['type_qid']
    org_country_qid = base_data['country_qid']
    website = base_data['website']
    org_inception = base_data['inception']
    latitude = base_data['latitude']
    longitude = base_data['longitude']
    org_aliases = grid_data.aliases_for_id(grid_id)
    org_labels = grid_data.labels_for_id(grid_id)

    statements = []
    statements.append(
        wdi_core.WDItemID(org_type_qid,
                          p_instance_of,
                          references=[reference_info]))
    statements.append(
        wdi_core.WDExternalID(grid_id, p_grid_id, references=[reference_info]))
    if org_country_qid:
        statements.append(
            wdi_core.WDItemID(org_country_qid,
                              p_country,
                              references=[reference_info]))
    if website and (len(website) < 500):
        statements.append(
            wdi_core.WDUrl(website,
                           p_official_website,
                           references=[reference_info]))
    if org_inception and (int(org_inception) > 900):
        org_inception_date = datetime.date(int(org_inception), 1, 1)
        statements.append(
            wdi_core.WDTime(
                org_inception_date.strftime('+%Y-%m-%dT%H:%M:%SZ'),
                p_inception,
                precision=9,
                references=[
                    reference_info
                ]))  # year-level precision in inception dates from GRID
    if latitude and longitude and (abs(latitude) <= 90.0) and (abs(longitude)
                                                               <= 360.0):
        precision = 1.0
        longitude_parts = str(longitude).split('.')
        if len(longitude_parts) > 1:
            exp = len(longitude_parts[1])
            precision = pow(10.0, -exp)
        statements.append(
            wdi_core.WDGlobeCoordinate(float(latitude),
                                       float(longitude),
                                       precision,
                                       p_coordinate_location,
                                       references=[reference_info]))
    wd_item = wdi_core.WDItemEngine(data=statements)
    wd_item.set_label(label=org_name, lang='en')
    wd_item.set_description(description=org_description, lang='en')
    if org_aliases and len(org_aliases) > 0:
        wd_item.set_aliases(org_aliases, lang='en')
    for label_hash in org_labels:
        if label_hash['language'] == 'en':
            wd_item.set_aliases([label_hash['label']], 'en', append=True)
        else:
            wd_item.set_label(label=label_hash['label'],
                              lang=label_hash['language'])
    new_item_id = wd_item.write(
        login_instance,
        edit_summary=
        'Creating item from GRID record via APSbot_grid_create script (APSbot task 3)'
    )
    print("created {0}".format(new_item_id))
示例#6
0
    def initiate(self):
        dfWikibaseItems = pd.DataFrame
        #wd_item = wdi_core.WDItemEngine(data=data) # create new item
        #wd_item.entity_metadata.get('id') #retriev item id
        columns_inst = [
            1, 7, 8, 9, 19, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
            24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37
        ]
        columns_Instituicao = [
            '_pageName', 'tipo', 'data_fundação', 'data_extinção',
            'paralisação_início', 'paralisação_fim', 'Localização1',
            'Localização_data_início1', 'Localização_data_fim1',
            'Localização2', 'Localização_data_início2',
            'Localização_data_fim2', 'Localização3',
            'Localização_data_início3', 'Localização_data_fim3',
            'Localização4', 'Localização_data_início4',
            'Localização_data_fim4', 'Localização5',
            'Localização_data_início5', 'Localização_data_fim5',
            'Localização6', 'Localização_data_início6',
            'Localização_data_fim6', 'Localização7',
            'Localização_data_início7', 'Localização_data_fim7',
            'Localização8', 'Localização_data_início8',
            'Localização_data_fim8', 'antecessora', 'sucessora'
        ]
        columns_Coordenada = ['_pageName', '1', '5']
        r_file = open(datasetpath + coord_file, 'rb').read()
        result = chardet.detect(r_file)
        file_encoding = result['encoding']
        dfInstituicao = pd.read_csv(datasetpath + instituicao_file,
                                    encoding=file_encoding,
                                    header=0,
                                    usecols=columns_inst)

        dfCoordenadas = pd.read_csv(datasetpath + coord_file,
                                    encoding=file_encoding,
                                    header=0,
                                    nrows=175,
                                    usecols=columns_Coordenada)

        dfCoordenadas_Encode = pd.read_csv(datasetpath + coord_file,
                                           encoding=file_encoding,
                                           header=0,
                                           skiprows=175)
        #,usecols=columns_Coordenada)

        dfCoordenadas = dfCoordenadas.reindex(
            columns=dfCoordenadas.columns.tolist())
        dataCoordNames = dfCoordenadas['_pageName'].replace(' ',
                                                            '_',
                                                            regex=True)
        #dataTemp = dataTemp.replace(['\[','\]'], ['',''], regex=True)
        coordenadas = {}
        #print(dataCoordNames.head(10))
        #frame = pd.DataFrame(dataTemp['_pageName'])
        #print(dataCoordNames.values)

        for i in range(len(dfCoordenadas)):
            coord_name = dfCoordenadas['_pageName']
            url_coord = URL_EVITERBO + dfCoordenadas['_pageName'].replace(
                ' ', '_', regex=True)
            lat = dfCoordenadas['1']
            long = dfCoordenadas['5']
            data = [
                wdi_core.WDUrl(prop_nr='P30', value=url_coord),
                wdi_core.WDGlobeCoordinate(prop_nr='P29',
                                           latitude=lat,
                                           longitude=long,
                                           precision=0.0001),
                wdi_core.WDString(prop_nr='P45',
                                  value=dfCoordenadas['_pageName'])
            ]
            # wd_item = wdi_core.WDItemEngine(data=data) # create new item
            # wd_item.set_label(label=dfCoordenadas['_pageName'],lang='pt')
            item_id = 'Q001'  #wd_item.entity_metadata.get('id') #retrieve item id
            # wd_item.write(self.login_instance)
            coordenadas = {
                'nome':
                dfCoordenadas['_pageName'],
                'urleviterbo':
                URL_EVITERBO +
                dfCoordenadas['_pageName'].replace(' ', '_', regex=True),
                'coord_1':
                dfCoordenadas['1'],
                'coord_5':
                dfCoordenadas['5'],
                'item_id':
                item_id
            }
示例#7
0
    if isinstance(row["familyKey"], int):
        item_data.append(
            wdi_core.WDExternalID(str(row["familyKey"]), prop_nr="P39"))
    if isinstance(row["genusKey"], int):
        item_data.append(
            wdi_core.WDExternalID(str(row["genusKey"]), prop_nr="P40"))
    if isinstance(row["subgenusKey"], int):
        item_data.append(
            wdi_core.WDExternalID(str(row["subgenusKey"]), prop_nr="P41"))
    if isinstance(row["speciesKey"], int):
        item_data.append(
            wdi_core.WDExternalID(str(row["speciesKey"]), prop_nr="P42"))
    if row["decimalLatitude"] != "":
        item_data.append(
            wdi_core.WDGlobeCoordinate(row["decimalLatitude"],
                                       row["decimalLongitude"],
                                       precision=0.016666666666667,
                                       prop_nr="P45"))

    for index2, row2 in multimediaSelection[multimediaSelection["gbifID"] ==
                                            row["gbifID"]].iterrows():
        qualifiers = []
        creatorQID = wdi_core.WDItemEngine.get_wd_search_results(
            search_string=row2["creator"], mediawiki_api_url=api)
        if len(creatorQID) == 0:
            creator_item = wdi_core.WDItemEngine(new_item=True,
                                                 mediawiki_api_url=api,
                                                 sparql_endpoint_url=sparql)
            creator_item.set_label(row2["creator"], lang="en")
            try_write(creator_item,
                      record_id=row2["creator"],
                      record_prop="",