avi-perl/Hebrew

Gematria Support

Closed this issue · 5 comments

I wish to add Gematria to this package.
Wonder where is the best place to do it?
From my point of view it should be in the Hebrew class.
what do you think?

I think Gematria should definitely be part of a package like this, and that the Hebrew class is the ideal place for it.

I have been working on a class to represent Hebrew characters. Besides for other functionality associated with particular characters, an instance of HebrewChar can contain values used for the various types of Gematria that is supported in Hebrew. Within Hebrew we can have a way of getting the string as an array of HebrewChar's which will allow us to perform the mathematical operations!

A very early version of this can be seen in the HebrewGlyph branch of this repo. I have already put more work into it and intend to continue work and push major updates tonight.

Contributions to the Gematria feature would be extremely welcome! I'll focus my efforts on getting things in place in the HebrewChar class so that you can begin to contribute if you choose to.

@yoavcaspi I've completed the work mentioned above and added the first gematria type, the most used, MISPAR_HECHRACHI. What follows is an overview of my implementation so that you may work on additional methods, but feel free to suggest changes to the way it has been implemented.

I'm going to leave this issue open for a while so there is a place for discussion if necessary.

Hebrew.gematria()

To get the gematria value for a Hebrew string, we use the Hebrew.gematria. The gematria function accepts a method parameter which defaults to MISPAR_HECHRACHI. Additional methods available are listed in the hebrew.gematria.GematriaTypes Enum.

Character Values

In order to calculate the gematria of a word or sentence, we need to know the value of each letter for that specific method of gematria. In hebrew.chars each letter used in Hebrew text is defined as a constant, this is a good place to codify the value of each letter. Rather than putting the value directly on each constant, a @property is used to look up the value in hebrew.gematria.

Because of how Hebrew.gematria was written and the way the values were defined in hebrew.gematria, it is necessary for the HebrewChar property name and the GematriaTypes value to match. I'm not particularly fond of this.

Testing

All tests related to gematria are within test_gematria.py. This includes tests related to gematria from any class to keep all tests related to this topic in one place.

Other

  • If the gematria method does not have separately defined values for final letters (sofit) the value should be explicitly defined as being the same as its nonfinal form.

Resources

I found this site to be a great resource for a list of gematria methods, how they are calculated, the values for each letter, and a calculator we can use as a source of truth for tests. Let's take all spelling from there.

I don't see the branch you are referring to in the repository.
Are you sure this branch is in the remote and not just locally?

The branch I referenced was removed after merging the code.

Closing this issue, Gimatria methods are slowly being added.