cltk: v0.1.28

Kyle Johnson, Martín Pozzi, Luke Hollis, Burns, Patrick J., Kirby, Tyler, Badger, The Gitter, Stephen Margheim, Eamonn Bell, AmitShilo · Zenodo (CERN European Organization for Nuclear Research) · 2015

About Addition of information retrieval module for pattern matching in text. From docs Several functions are available for querying text in order to match regular expression patterns. match_regex() is the most basic. Punctuation rules are included for texts using Latin sentence–final punctuation ('.', '!', '?') and Greek ('.', ';'). For returned strings, you may choose between a context of the match's sentence, paragraph, or custom number of characters on each side of a hit. Note that this function and the next each return a generator. Here is an example in Latin with a sentence context, case-insensitive: In [1]: from cltk.ir.query import match_regex In [2]: text = 'Ita fac, mi Lucili; vindica te tibi. et tempus, quod adhuc aut auferebatur aut subripiebatur aut excidebat, collige et serva.' In [3]: matches = match_regex(text, r'tempus', language='latin', context='sentence', case_insensitive=True) In [4]: for match in matches: print(match) ...: et *tempus*, quod adhuc aut auferebatur aut subripiebatur aut excidebat, collige et serva. And here with context of 40 characters: In [5]: matches = match_regex(text, r'tempus', language='latin', context=40, case_insensitive=True) In [6]: for match in matches: print(match) ...: Ita fac, mi Lucili; vindica te tibi. et *tempus*, quod adhuc aut auferebatur aut subripi For querying the entirety of a corpus, see search_corpus(), which returns a tuple of ('author_name': 'match_context'). In [7]: from cltk.ir.query import search_corpus In [8]: for match in search_corpus('ὦ ἄνδρες Ἀθηναῖοι', 'tlg', context='sentence'): print(match) ...: ('Ammonius Phil.', ' καλοῦντας ἑτέρους ἢ προστάσσοντας ἢ ἐρωτῶντας ἢ εὐχομένους περί τινων, πολλάκις δὲ καὶ αὐτοπροσώπως κατά τινας τῶν ἐνεργειῶν τούτων ἐνεργοῦ- σι “πρῶτον μέν, *ὦ ἄνδρες Ἀθηναῖοι*, τοῖς θεοῖς εὔχομαι πᾶσι καὶ πάσαις” λέγοντες ἢ “ἀπόκριναι γὰρ δεῦρό μοι ἀναστάς”. οἱ οὖν περὶ τῶν τεχνῶν τούτων πραγματευόμενοι καὶ τοὺς λόγους εἰς θεωρίαν ') ('Sopater Rhet.', "θόντα, ἢ συγγνωμονηκέναι καὶ ἐλεῆσαι. ψυχῆς γὰρ πάθος ἐπὶ συγγνώμῃ προτείνεται. παθητικὴν οὖν ποιή- σῃ τοῦ πρώτου προοιμίου τὴν ἔννοιαν: ἁπάντων, ὡς ἔοι- κεν, *ὦ ἄνδρες Ἀθηναῖοι*, πειρασθῆναί με τῶν παραδό- ξων ἀπέκειτο, πόλιν ἰδεῖν ἐν μέσῃ Βοιωτίᾳ κειμένην. καὶ μετὰ Θήβας οὐκ ἔτ' οὔσας, ὅτι μὴ στεφανοῦντας Ἀθη- ναίους ἀπέδειξα παρὰ τὴ") …

Read the paper · More papers on PaperTik