File size: 1,112 Bytes
a2e1879
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
from typing import Iterable


ASCII_UPPERCASE = set("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
ASCII_LOWERCASE = set("abcdefghijklmnopqrstuvwxyz")
ASCII_LETTERS = ASCII_UPPERCASE | ASCII_LOWERCASE


def get_text_from_args_or_stdin(argv: Iterable[str]) -> str:
	text_parts = list(argv)
	if text_parts:
		return " ".join(text_parts)

	# If input is piped, read from stdin. Otherwise, prompt the user.
	if not sys.stdin.isatty():
		return sys.stdin.read().strip()

	try:
		return input("Enter text to check if it's English: ").strip()
	except EOFError:
		return ""


def is_english_by_ascii_letters_only(text: str) -> bool:
	"""
	Basic heuristic: If every alphabetic character in the text is an ASCII letter (A-Z or a-z),
	consider it English. Digits, whitespace, and punctuation are ignored.
	"""
	for ch in text:
		if ch.isalpha() and ch not in ASCII_LETTERS:
			return False
	return True


def main() -> int:
	text = get_text_from_args_or_stdin(sys.argv[1:])
	if is_english_by_ascii_letters_only(text):
		print("English")
		return 0
	print("Not English")
	return 0


if __name__ == "__main__":
	sys.exit(main())