Skip to content

Commit

Permalink
added cols support for get database
Browse files Browse the repository at this point in the history
  • Loading branch information
markomanninen committed Apr 4, 2018
1 parent ec46390 commit 027b618
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 50 deletions.
42 changes: 30 additions & 12 deletions README
Expand Up @@ -11,17 +11,35 @@ pip install grcriddles
Use from Python/IPython console:

```python
# import database getter
from grcriddles import get_database
a = get_database()
# filter words
a = a[a[0].str.contains("ΑΜΦΕΚΑΛΥ")]
# sort and print word info
words = a.sort_values(0)
words = words[[0, 1, 3, 4, 5, 7, 8]]
words.columns = ['Word', 'Count', 'Chars', 'Isopsephy', 'Syllables', 'Vowels', 'Mutes']
words.set_index('Word', inplace=True)
words
# get words with length 9, isopsephy 1697, consonants 5,
# and the first three syllables having 2 letters each
# syllable count is going to be 4 with above parameters
words = get_database({0: 'Word', 1: 'Count', 3: 'Chars', 4: 'Isopsephy', 5: 'Syllables', 7: 'Vowels', 8: 'Mutes'})
a = words[words['Isopsephy'] == 1697]
a = a[a['Chars'] == 9]
a = a[a['Mutes'] == 5]
a = a[a.apply(lambda x: len(x['Syllables'][0]) == 2 and \
len(x['Syllables'][1]) == 2 and \
len(x['Syllables'][2]) == 2, axis=1)]
# output words ordered alphabetically
a.sort_index()
```

Output:

```txt
Count Chars Isopsephy Syllables Vowels Mutes
Word
ΑΜΦΕΚΑΛΥΨ 1 9 1697 [ΑΜ, ΦΕ, ΚΑ, ΛΥΨ] 4 5
ΛΗΛΥΘΟΤΩΝ 1 9 1697 [ΛΗ, ΛΥ, ΘΟ, ΤΩΝ] 4 5
ΜΕΤΑΝΑΣΤΩ 1 9 1697 [ΜΕ, ΤΑ, ΝΑ, ΣΤΩ] 4 5
ΣΥΝΩΚΙΣΘΗ 13 9 1697 [ΣΥ, ΝΩ, ΚΙ, ΣΘΗ] 4 5
```

```python
# get words containing ΑΜΦΕΚΑΛΥ stem word
b = words.filter(like="ΑΜΦΕΚΑΛΥ", axis=0)
b.sort_index()
```

Output:
Expand All @@ -38,7 +56,7 @@ Word
ΑΜΦΕΚΑΛΥΨΕΝ 20 11 1752 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΨΕΝ] 5 6
```

Docs:
### Docs

Developer documentation: http://grcriddles.readthedocs.io/en/latest/

Expand Down
42 changes: 30 additions & 12 deletions README.md
Expand Up @@ -11,17 +11,35 @@ pip install grcriddles
Use from Python/IPython console:

```python
# import database getter
from grcriddles import get_database
a = get_database()
# filter words
a = a[a[0].str.contains("ΑΜΦΕΚΑΛΥ")]
# sort and print word info
words = a.sort_values(0)
words = words[[0, 1, 3, 4, 5, 7, 8]]
words.columns = ['Word', 'Count', 'Chars', 'Isopsephy', 'Syllables', 'Vowels', 'Mutes']
words.set_index('Word', inplace=True)
words
# get words with length 9, isopsephy 1697, consonants 5,
# and the first three syllables having 2 letters each
# syllable count is going to be 4 with above parameters
words = get_database({0: 'Word', 1: 'Count', 3: 'Chars', 4: 'Isopsephy', 5: 'Syllables', 7: 'Vowels', 8: 'Mutes'})
a = words[words['Isopsephy'] == 1697]
a = a[a['Chars'] == 9]
a = a[a['Mutes'] == 5]
a = a[a.apply(lambda x: len(x['Syllables'][0]) == 2 and \
len(x['Syllables'][1]) == 2 and \
len(x['Syllables'][2]) == 2, axis=1)]
# output words ordered alphabetically
a.sort_index()
```

Output:

```txt
Count Chars Isopsephy Syllables Vowels Mutes
Word
ΑΜΦΕΚΑΛΥΨ 1 9 1697 [ΑΜ, ΦΕ, ΚΑ, ΛΥΨ] 4 5
ΛΗΛΥΘΟΤΩΝ 1 9 1697 [ΛΗ, ΛΥ, ΘΟ, ΤΩΝ] 4 5
ΜΕΤΑΝΑΣΤΩ 1 9 1697 [ΜΕ, ΤΑ, ΝΑ, ΣΤΩ] 4 5
ΣΥΝΩΚΙΣΘΗ 13 9 1697 [ΣΥ, ΝΩ, ΚΙ, ΣΘΗ] 4 5
```

```python
# get words containing ΑΜΦΕΚΑΛΥ stem word
b = words.filter(like="ΑΜΦΕΚΑΛΥ", axis=0)
b.sort_index()
```

Output:
Expand All @@ -38,7 +56,7 @@ Word
ΑΜΦΕΚΑΛΥΨΕΝ 20 11 1752 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΨΕΝ] 5 6
```

Docs:
### Docs

Developer documentation: http://grcriddles.readthedocs.io/en/latest/

Expand Down
64 changes: 42 additions & 22 deletions doc/appendix2.rst
Expand Up @@ -5,29 +5,49 @@ Minimum code to solve isopsephical riddles in the Pseudo-Sibylline oracles. This
requires `functions.py` script and `greek_words_corpora.csv` file reside in the
same directory.

.. code-block:: python
.. code-block:: bash
from functions import get_database
pip install grcriddles
# get words with length 9, isopsephy 1697, syllable count 4, consonants 5,
# and the first three syllables having 2 letters each
a = get_database()
a = a[a[4] == 1697]
a = a[a[3] == 9]
a = a[a[6] == 4]
a = a[a[8] == 5]
a = a[a.apply(lambda x: len(x[5][0]) == 2 and len(x[5][1]) == 2 and len(x[5][2]) == 2, axis=1)]
.. code-block:: python
from grcriddles import get_database
# get words with length 9, isopsephy 1697, consonants 5,
# and the first three syllables having 2 letters each
# syllable count is going to be 4 with above parameters
words = get_database({0: 'Word', 1: 'Count', 3: 'Chars', 4: 'Isopsephy', 5: 'Syllables', 7: 'Vowels', 8: 'Mutes'})
a = words[words['Isopsephy'] == 1697]
a = a[a['Chars'] == 9]
a = a[a['Mutes'] == 5]
a = a[a.apply(lambda x: len(x['Syllables'][0]) == 2 and \
len(x['Syllables'][1]) == 2 and \
len(x['Syllables'][2]) == 2, axis=1)]
# output words ordered alphabetically
words = a.sort_values(0)
words = words[[0, 1, 3, 4, 5, 7, 8]]
words.columns = ['Word', 'Count', 'Letters', 'Isopsephy', 'Syllables', 'Vowels', 'Consonants']
words.set_index('Word', inplace=True)
words
# search exact match(es) for the word
from functions import search_words_from_corpora, perseus_dir, first1k_dir
search_words_from_corpora(["ΑΜΦΕΚΑΛΥΨ"], [perseus_dir, first1k_dir], None, True)
# search partial match(es) for the word
search_words_from_corpora(["ΑΜΦΕΚΑΛΥΨ"], [perseus_dir, first1k_dir], None, False)
a.sort_index()
.. code-block:: text
Count Chars Isopsephy Syllables Vowels Mutes
Word
ΑΜΦΕΚΑΛΥΨ 1 9 1697 [ΑΜ, ΦΕ, ΚΑ, ΛΥΨ] 4 5
ΛΗΛΥΘΟΤΩΝ 1 9 1697 [ΛΗ, ΛΥ, ΘΟ, ΤΩΝ] 4 5
ΜΕΤΑΝΑΣΤΩ 1 9 1697 [ΜΕ, ΤΑ, ΝΑ, ΣΤΩ] 4 5
ΣΥΝΩΚΙΣΘΗ 13 9 1697 [ΣΥ, ΝΩ, ΚΙ, ΣΘΗ] 4 5
.. code-block:: python
# get words containing ΑΜΦΕΚΑΛΥ stem word
b = words.filter(like="ΑΜΦΕΚΑΛΥ", axis=0)
b.sort_index()
.. code-block:: text
Count Chars Isopsephy Syllables Vowels Mutes
Word
ΑΜΦΕΚΑΛΥΠΤΕ 3 11 1382 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΠΤΕ] 5 6
ΑΜΦΕΚΑΛΥΠΤΟΝ 2 12 1497 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΠΤΟΝ] 5 7
ΑΜΦΕΚΑΛΥΦΘΗ 2 11 1514 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΦΘΗ] 5 6
ΑΜΦΕΚΑΛΥΨ 1 9 1697 [ΑΜ, ΦΕ, ΚΑ, ΛΥΨ] 4 5
ΑΜΦΕΚΑΛΥΨΑΝ 2 11 1748 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΨΑΝ] 5 6
ΑΜΦΕΚΑΛΥΨΕ 18 10 1702 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΨΕ] 5 5
ΑΜΦΕΚΑΛΥΨΕΝ 20 11 1752 [ΑΜ, ΦΕ, ΚΑ, ΛΥ, ΨΕΝ] 5 6
11 changes: 11 additions & 0 deletions doc/appendix3.rst
@@ -0,0 +1,11 @@
Appendix 3 - Search results
===========================

.. code-block:: python
# search exact match(es) for the word from both perseus and first1k corpora
from functions import search_words_from_corpora, perseus_dir, first1k_dir
search_words_from_corpora(["ΑΜΦΕΚΑΛΥΨ"], [perseus_dir, first1k_dir], None, True)
# search partial match(es) for the word from both perseus and first1k corpora
search_words_from_corpora(["ΑΜΦΕΚΑΛΥΨ"], [perseus_dir, first1k_dir], None, False)
2 changes: 1 addition & 1 deletion grcriddles/__init__.py
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# file: __init__.py

__version__ = "0.1.4"
__version__ = "0.1.6"

from .functions import Abnum, greek, syllabify, Counter, HTML, display_html, \
display_side_by_side, remove, download_with_indicator, \
Expand Down
13 changes: 11 additions & 2 deletions grcriddles/functions.py
Expand Up @@ -295,7 +295,7 @@ def get_stats(fl):
return ccontent, chars, lwords

# get word database
def get_database():
def get_database(cols = None):
global database
if not database:
# try to read from the current directory
Expand All @@ -313,7 +313,16 @@ def get_database():
df[7] = df[7].apply(lambda x: int(x))
df[8] = df[8].apply(lambda x: int(x))
database = df
return database.copy()
# rename columns and set index
if cols:
words = database.copy()
words = words[list(cols.keys())]
words.columns = list(cols.values())
if 0 in cols:
words.set_index(cols[0], inplace=True)
return words
else:
return database.copy()

# display tables side by side, jupyter notebook helper
def display_side_by_side(**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -6,7 +6,7 @@

#python setup.py sdist upload

version = 'v0.1.5'
version = 'v0.1.6'

name = 'grcriddles'

Expand Down

0 comments on commit 027b618

Please sign in to comment.