8000 Romanize strings via python script · Issue #9 · isi-nlp/uroman · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Romanize strings via python script #9

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

Closed
ryderwishart opened this issue Jun 21, 2023 · 1 comment
Closed

Romanize strings via python script #9

ryderwishart opened this issue Jun 21, 2023 · 1 comment

Comments

@ryderwishart
Copy link

In case someone else finds it useful, here's a script for romanizing strings through python. This script will download the release and unzip it, so you should be able to just run it to test:

import os
import zipfile
import requests
import subprocess

# Downloading the zip file
url = 'https://github.com/isi-nlp/uroman/archive/refs/tags/v1.2.8.zip'
zip_filename = 'uroman.zip'
with open(zip_filename, 'wb') as zip_file:
    response = requests.get(url)
    zip_file.write(response.content)

# Unzipping the downloaded file
with zipfile.ZipFile(zip_filename, 'r') as zip_ref:
    zip_ref.extractall()

# Function to call the unzipped code
def uroman(input_string, language=None, chart=False):
    script_path = 'uroman-1.2.8/bin/uroman.pl'  # Adjust if necessary
    command = ["perl", script_path]

    # Add language flag if specified
    if language:
        command.extend(["-l", language])
    
    # Add chart flag if specified
    if chart:
        command.append("--chart")
    
    process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate(input=input_string.encode())

    if process.returncode != 0:
        # There was an error
        print(f"Error code {process.returncode}: {stderr.decode()}")
        return None

    # Return the output as a string
    return stdout.decode()

# Example usage
print(uroman("Ἰησοῦς Χριστός κύριος"))
@uhermjakob
Copy link
Contributor

Thanks. Responding to growing interest in a Python version, I reimplemented uroman in Python and made it available on PyPI so that people can install it more easily ("pip install uroman").

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

No branches or pull requests

2 participants
0