Exemplo n.º 1
0
def semshift(search_term):
    r = requests.get(
        f'https://csd.clld.org/parameters?sEcho=9&iColumns=4&sColumns=more%2Cname%2Csemantic_domain%2Cpart_of_speech&sSearch_1={search_term}&bRegex_1=false&bSearchable_1=true',
        headers={
            'accept': 'application/json',
            'x-requested-with': 'XMLHttpRequest'
        })

    meanings = []
    try:
        etyma = [
            html.fromstring(item[1]).attrib['href'].split('/')[-1]
            for item in json.loads(r.content)['aaData']
        ]
        if len(etyma) == 0:
            return []

        urls = [
            f'https://csd.clld.org/values?parameter={etym}&sEcho=1&iColumns=6&sColumns=language%2Cname%2Cphonetic%2Cdescription%2Ccomment%2Csources'
            for etym in etyma
        ]
        results = multi_request(urls,
                                headers={
                                    'accept': 'application/json',
                                    'x-requested-with': 'XMLHttpRequest'
                                })

        for result in results:
            meanings += [
                item[-3] for item in json.loads(result.content)['aaData']
            ]
    except json.decoder.JSONDecodeError:
        pass
    return list(set(meanings))
Exemplo n.º 2
0
def semshift(search_term):
    r = requests.get(
        f'https://stedt.berkeley.edu/~stedt-cgi/rootcanal.pl/search/ajax?tbl=etyma&s={search_term}&f=&lg=&as_values_lg-auto=',
        headers={'accept': 'application/json'})
    meanings = []
    try:
        ids = [item[0] for item in json.loads(r.content)['data']]

        if len(ids) == 0:
            return []
        urls = [
            f'https://stedt.berkeley.edu/~stedt-cgi/rootcanal.pl/etymon/{id}'
            for id in ids
        ]
        results = multi_request(urls)

        for r2 in results:
            tree2 = html.fromstring(r2.content)
            meanings += tree2.xpath(
                '/html/body/table[2]/tbody/tr/td[5]/text()')

    except json.decoder.JSONDecodeError:
        pass

    return list(set(meanings))
Exemplo n.º 3
0
def reverse(search_term):
    r = requests.get(
        f'https://stedt.berkeley.edu/~stedt-cgi/rootcanal.pl/search/ajax?tbl=lexicon&s={search_term}&f=&lg=&as_values_lg-auto=',
        headers={'accept': 'application/json'})
    proto_nums = set([
        first_numeric(elem[1]) for elem in json.loads(r.content)['data']
        if elem[1] != None
    ])
    proto_nums.discard(0)

    if len(proto_nums) == 0:
        return []

    meanings = []
    urls = [
        f'https://stedt.berkeley.edu/~stedt-cgi/rootcanal.pl/etymon/{num}'
        for num in proto_nums
    ]
    results = multi_request(urls)

    for r2 in results:
        tree2 = html.fromstring(r2.content)
        meanings.append(
            trim(tree2.xpath('/html/body/table[1]/tr/td/h1/text()')[0]))

    return meanings
Exemplo n.º 4
0
def semshift(search_term):
    r = requests.get(f'https://clics.clld.org/parameters?sEcho=9&iColumns=7&sColumns=%23%2Cname%2C%23%2Ccount_varieties%2Ccount_colexifications%2Cinfomap%2Csubgraph&iDisplayStart=0&iDisplayLength=100&mDataProp_1=1&sSearch_1={search_term}',
                     headers={'accept': 'application/json', 'x-requested-with': 'XMLHttpRequest'})
    urls = [html.fromstring(item[1]).attrib['href'] for item in json.loads(r.content)['aaData']]

    results = multi_request(urls)
    meanings = []
    for result in results:
        tree = html.fromstring(result.content)
        meanings += tree.xpath('//*[@class="Edge"]/text()')

    return meanings
Exemplo n.º 5
0
    def reverse(self, search_term):
        if len(self.target_phrases) == 0:
            self.populate_targets()
        urls = [
            f'http://datsemshift.ru/search?target={quote(input)}'
            for input in self.target_phrases if search_term in input
        ]

        results = multi_request(urls)

        meanings = [
            item for sublist in [
                html.fromstring(r.content).xpath(
                    '/html/body/main/div/table/tr/td[3]/text()')
                for r in results
            ] for item in sublist if item != 'Meaning 1'
        ]

        return meanings
Exemplo n.º 6
0
    def semshift(self, search_term):
        if len(self.source_phrases) == 0:
            self.populate_sources()
        urls = [
            f'http://datsemshift.ru/search?source={quote(source_phrase)}'
            for source_phrase in self.source_phrases
            if search_term in source_phrase
        ]

        results = multi_request(urls)

        meanings = [
            item for sublist in [
                html.fromstring(r.content).xpath(
                    '/html/body/main/div/table/tr/td[5]/text()')
                for r in results
            ] for item in sublist if item != 'Meaning 2'
        ]

        return meanings