Schlaumra / linguee-parser

A Linguee Parser
GNU General Public License v3.0
0 stars 0 forks source link

How to access just the examples #1

Open tomsturges opened 2 years ago

tomsturges commented 2 years ago

Hello, could I kindly ask you if you would be able to explain how I access only the 'examples' with your code. In other words I would like to be able to write something like parser.get_dictionary()['gut','examples'] and it would return

[('Dieser Roman ist ein gutes Beispiel für Kinderliteratur.', "This novel is a fine example of children's literature.") .......

Thanks

Schlaumra commented 2 years ago

Hi, currently this library is very simple. It just returns one python dictionary structure. To get the examples you need to access it through indexes like the following:

Access Examples of first part_of_speech (highlighted on the website with blue color followed by for example verb), the first translation (for all examples use for loop) image

parser.search('run')['foreign_term'][0]['translation'][0]
# Returns [('I had to run really fast to catch the bus this morning.', 'Ich musste heute Morgen richtig schnell laufen, um den Bus noch zu erwischen.'), ('This power plant runs on biogas.', 'Dieses Kraftwerk läuft mit Biogas.')]

Example Code to get explore structure:

import pprint
from lingueeParser import linguee

parser = linguee.Linguee(("english", "german"))

pp = pprint.PrettyPrinter(indent=1)
pp.pprint(parser.search('run'))