Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic analysis of the script content of strings #764

Merged
merged 2 commits into from
Mar 30, 2021

Conversation

jwiggins
Copy link
Member

This is another part of #762

There are two pieces here, and a ton of machine-generated code (don't fear the diff):

  • A small program which fetches http://www.unicode.org/Public/UNIDATA/Scripts.txt, parses it, and writes out the kiva.fonttools.text._data module.
  • A new class UnicodeAnalyzer which uses the data from Scripts.txt and returns the languages and slices for a given input string.

UnicodeAnalyzer is pretty basic right now. I'd like to keep it that way in this PR. For instance, Emoji ligatures are not great:

In [3]: s = "👩‍👩‍👧‍👧" 

In [4]: s                                                                       
Out[4]: '👩\u200d👩\u200d👧\u200d👧'

In [5]: an.languages(s)                                                         
Out[5]: 
[(0, 1, 'Common'),
 (1, 2, 'Inherited'),
 (2, 3, 'Common'),
 (3, 4, 'Inherited'),
 (4, 5, 'Common'),
 (5, 6, 'Inherited'),
 (6, 7, 'Common')]

Comment on lines +113 to +114
94: "Tai_Le",
95: "New_Tai_Lue",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were changed to match the names in kiva.fonttools.text._data.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


def _lookup_codepoint(self, cp):
comps = self.ranges - ord(cp)
index = ((comps[:, 0] <= 0) == (comps[:, 1] >= 0)).argmax()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the most important detail in the PR - how we're selecting the entry given a code point - and it'd be useful if you could elaborate on how we're doing it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

@rahulporuri
Copy link
Contributor

still LGTM

@jwiggins jwiggins merged commit ffd2535 into master Mar 30, 2021
@jwiggins
Copy link
Member Author

Thanks for the review

@jwiggins jwiggins deleted the feature/language-parse branch March 30, 2021 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants