input_files = [] if args.input: for i in args.input: input_files.append(i) elif args.input_directory: for root, dirs, files in os.walk(args.input_directory): for filename in files: if filename.endswith( ".conllu") and args.lang_code in filename.split( ".conllu")[0].split("_"): input_files.append(os.path.join(root, filename)) global lang_code lang_code = args.lang_code try: setup(lang_code) except PermissionError: print( "Downloading Models Failed. Please make sure you have enough privileges to create a directory.\n" "For debugging, run the Language Code Setup using python interpreter.\n" "Useful Links- \n" "1. https://inltk.readthedocs.io/en/latest/api_docs.html#setup-the-language\n" "2. https://github.com/caffe2/models/issues/16\n", file=stderr) exit(1) all_lexemes = dict() compound_lexemes = dict() for infile in tqdm.tqdm(input_files): all_lexemes, compound_lexemes = process_conllu(infile, all_lexemes, compound_lexemes)
import re import string import pandas as pd from inltk.inltk import get_similar_sentences from inltk.inltk import setup setup('pa') df = pd.read_csv(r'pan_words.csv') Wordslist = df['word'].tolist() original_text = """ਨੂੰ ਅੰਗਰਜ਼ੀ ਉੱਤਤੇ ਨਿਭਰਰਤਾ ਤੋਂ ਪੂਰਨ ਰੂਪ ਵਿੱਚ ਮਕਤੀ ਮਿਲ ਜਵੇਗੀ। ਯੂਨੀਕੋਡ ਪ੍ਰਣਾਲੀ ਦੀਮਦਦ ਨਾਲ ਕਿਸੇਵੀ ਭਾਸ਼ਾ ਵਿੱਚ ਕੰਪਿਊਟਰ ਪ੍ਰੋਗਰਾਮ ਬਣਾਏ ਜਾ ਸਰਦੇ ਹਨ। ਇਸ ਨਵੀਂ ਤਕਨੀਕ ਦੇ ਵਿਕਸਿਤ ਹੋਣ ਨਾਲ ਹੁਣ ਕੋ ਈ ਵਿਅਕਤੀਇਕ ਕੰਪਿਊਟਰ ਤੋਂ ਦੂਮਰੇ ਕੰਪਿਊਟਰ ਵਿੱਚ ਗੁਰਮੁਖੀ ਅਕੜਿਆਂ ਦਾ ਸਥਾਨੰਤਰਨ ਬਿਨਾਂ ਕਿਸੇ ਨੁਕਸਾਨ ਦੇ ਅਤੇ ਫੌਂਟ ਦੀ ਚਿੰਤਾ ਕੀਤੇ ਬਿਨਾਂ ਕਰ ਸਕਦਾ ਹੈ। ਯੂਨੀਕੋਡ ਫੌਂਟ ਵਿਚ ਤਿਆ ਰ ਕੀਤਾ ਡਾਟਾ ਬੇਸ ਵਰਣਾ ਬਹੁਤ ਆਸ਼ਾਨ ਹੈ। ਵਰਤਮਾਨਸਮੇਂ ਵਿੱਚ ਮੋਬਾਇਲ ਫ਼ੋਨਂ , ਪਅਲੇਰ, ਫ਼ੋਨ-ਬਾਕਸ ਮੈਸੇਜ ਬੋਰਡ ਆਦਿ ਪੂਰੀ ਤਰ੍ਹਾਂ ਯੂਨੀਕੋਡ ਅਨੁਕੂਲ ਹੋ ਰਹੇ ਹਨ। ਯੂ ਨੀਕੋਡ ਅਨੁਕੂਲ ਕਿਸੇ ਵੀ ਕੰਪਿਊਟਰ ਵਿੱਚ""" modified_text = original_text text = original_text print("Given text is==>\n", original_text) text = re.sub('\[.*?\]', '', text) text = re.sub('।', '', text) text = re.sub('[%s]' % re.escape(string.punctuation), '', text) text = re.sub('\w*\d\w*', '', text) from inltk.inltk import tokenize textwords = tokenize(text, "pa") temp = [] for i in textwords:
from inltk.inltk import setup #Native Languages #Hindi setup('hi') #Panjabi setup('pa') #Sanskrit setup('sa') #Gujarati setup('gu') #Kannada setup('kn') #Malayalam setup('ml') #Nepali setup('ne') #Oriya setup('or') #Marathi setup('mr') #Bengali setup('bn')
from inltk.inltk import setup import nltk import wget import zipfile setup('hi') nltk.download('punkt') nltk.download('averaged_perceptron_tagger') nltk.download('indian') nltk.download('stopwords') wget.download('https://ndownloader.figshare.com/files/24546650', out='model/model.zip') with zipfile.ZipFile('model/model.zip', 'r') as zip_ref: zip_ref.extractall('model/') print('Uncompressing Completed!')
file_contents = f.read() print (file_contents) f = open('./tamil.txt', 'r') file_contents1 = f.read() print (file_contents1) from inltk.inltk import setup from inltk.inltk import identify_language from inltk.inltk import identify_language, reset_language_identifying_models from inltk.inltk import predict_next_words from inltk.inltk import remove_foreign_languages from inltk.inltk import get_sentence_encoding from inltk.inltk import get_similar_sentences from inltk.inltk import get_sentence_similarity setup('hi') setup('bn') setup('pa') setup('sa') """# **Monolingual** **language** **identification**""" identify_language(file_contents) identify_language(file_contents1) identify_language("আবহাওয়া চমৎকার") identify_language("ਤੁਸੀ ਕਿਵੇਂ ਹੋ") identify_language("भवान् संस्कृतं भाषते वा ")
from inltk.inltk import setup from inltk.inltk import predict_next_words # download models for Hindi setup('bn') # predict the next words of the sentence "The weather is nice today" predict_next_words("भारत एक अद्भुत देश है", 10, "hi", 0.7)
def test(): from inltk.inltk import setup setup('hi')
# Example 2 - Predict Next 'n' Words, Get Similar Sentences from inltk.inltk import setup from inltk.inltk import predict_next_words from inltk.inltk import get_similar_sentences ''' Note: You need to run setup('<code-of-language>') when you use a language for the FIRST TIME ONLY. This will download all the necessary models required to do inference for that language. ''' setup('ta') example_sent = "உங்களைப் பார்த்து நிறைய நாட்கள் ஆகிவிட்டது" # Predict next 'n' tokens n = 5 pred_sent = predict_next_words(example_sent, n, 'ta') # Get 'n' similar sentence n = 2 simi_sent = get_similar_sentences(example_sent, n, 'ta') print("Predicted Words:", pred_sent) print("Similar Sentences:", simi_sent)
from inltk.inltk import setup setup('kn')