예제 #1
0
파일: extensions.py 프로젝트: pannous/angle
	def __getattr__(self, name):
		if str(name) in globals():
			method = globals()[str(name)]  # .method(m)
			try:
				return method(self)
			except:
				xlist(map(method, self))
		return self.method_missing(name)
예제 #2
0
	def __getattr__(self, name):
		if str(name) in globals():
			method = globals()[str(name)]  # .method(m)
			try:
				return method(self)
			except:
				xlist(map(method, self))
		return self.method_missing(name)
예제 #3
0
	def method_missing(xs, name, *args, **kwargs):  # [2.1,4.8].int=[2,5]
		if len(xs) == 0: return None
		try:
			method = getattr(xs.first(), name)
		except:
			# if str(name) in globals():
			method = globals()[str(name)]  # .method(m)
		if not callable(method):
			properties = xlist(map(lambda x: getattr(x, name), xs))
			return xlist(zip(xs, properties))
		# return properties
		return xlist(map(lambda x: method(args, kwargs), xs))  # method bound to x
예제 #4
0
파일: extensions.py 프로젝트: pannous/angle
	def method_missing(xs, name, *args, **kwargs):  # [2.1,4.8].int=[2,5]
		if len(xs) == 0: return None
		try:
			method = getattr(xs.first(), name)
		except:
			# if str(name) in globals():
			method = globals()[str(name)]  # .method(m)
		if not callable(method):
			properties = xlist(map(lambda x: getattr(x, name), xs))
			return xlist(zip(xs, properties))
		# return properties
		return xlist(map(lambda x: method(args, kwargs), xs))  # method bound to x
예제 #5
0
def drop_comments():
	in_comment_block = False
	in_comment_line = False
	i = 0
	prev = ""
	for token in extensions.xlist(the.tokenstream):
		is_beginning_of_line = token[2][1] == 0  # 1??
		# line = token[4]
		str = token[1]
		token_type = token[0]
		if str == "//" or str == "#":
			x_comment(token)
			in_comment_line = True
		elif str == '\n':
			in_comment_line = False
		elif prev == "*" and str.endswith("/"):
			x_comment(token)
			in_comment_block = False
		elif in_comment_block or in_comment_line:
			x_comment(token)
		elif prev == "/" and str.startswith("*"):
			i = i - 1  # drop prev_token too!!
			x_comment(prev_token)  # '/' too ;)
			x_comment(token)
			in_comment_block = True
		else:
			# token[-1] =i #renumber!! 'tuple' object does not support item assignment
			the.tokenstream[i] = (token[0], token[1], token[2], token[3], token[4], i)  # renumber!!
			i = i + 1
		prev = str
		prev_token = token
예제 #6
0
def drop_comments():
	in_comment_block = False
	in_comment_line = False
	i = 0
	prev = ""
	for token in extensions.xlist(the.tokenstream):
		is_beginning_of_line = token[2][1] == 0  # 1??
		# line = token[4]
		str = token[1]
		token_type = token[0]
		if str == "//" or str == "#":
			x_comment(token)
			in_comment_line = True
		elif str == '\n':
			in_comment_line = False
		elif prev == "*" and str.endswith("/"):
			x_comment(token)
			in_comment_block = False
		elif in_comment_block or in_comment_line:
			x_comment(token)
		elif prev == "/" and str.startswith("*"):
			i = i - 1  # drop prev_token too!!
			x_comment(prev_token)  # '/' too ;)
			x_comment(token)
			in_comment_block = True
		else:
			# token[-1] =i #renumber!! 'tuple' object does not support item assignment
			the.tokenstream[i] = (token[0], token[1], token[2], token[3], token[4], i)  # renumber!!
			i = i + 1
		prev = str
		prev_token = token
예제 #7
0
파일: extensions.py 프로젝트: pannous/angle
def xx(y):
	if type_name(y).startswith('x'):   return y
	# if isinstance(y, xstr):   return y
	# if isinstance(y, xlist):   return y
	if isinstance(y, xrange): return xlist(y)
	if isinstance(y, bool):  return y  # xbool(y)
	if isinstance(y, list):  return xlist(y)
	if isinstance(y, str):   return xstr(y)
	if isinstance(y, unicode):   return xstr(y)
	if isinstance(y, dict):  return xdict(y)
	if isinstance(y, float): return xfloat(y)
	if isinstance(y, int):   return xint(y)
	if isinstance(y, file):   return xfile(y)
	if isinstance(y, char):  return xchar(y)
	if isinstance(y, byte):  return xchar(y)
	if py3 and isinstance(y, range): return xlist(y)
	print("No extension for type %s" % type(y))
	return y
예제 #8
0
def xx(y):
	if type_name(y).startswith('x'):   return y
	# if isinstance(y, xstr):   return y
	# if isinstance(y, xlist):   return y
	if isinstance(y, xrange): return xlist(y)
	if isinstance(y, bool):  return y  # xbool(y)
	if isinstance(y, list):  return xlist(y)
	if isinstance(y, str):   return xstr(y)
	if isinstance(y, unicode):   return xstr(y)
	if isinstance(y, dict):  return xdict(y)
	if isinstance(y, float): return xfloat(y)
	if isinstance(y, int):   return xint(y)
	if isinstance(y, file):   return xfile(y)
	if isinstance(y, char):  return xchar(y)
	if isinstance(y, byte):  return xchar(y)
	if py3 and isinstance(y, range): return xlist(y)
	print("No extension for type %s" % type(y))
	return y
예제 #9
0
 def _all(self, name, instances=False, deep=False, reload=False):
     if isinstance(name, int):
         n = self.get(name)
         if not n.is_abstract: return n
         else: name = str(name)  # id
     if is_plural(name):
         return self._all(singular(name))
     if name in self.caches:
         return self.caches[name]
     file = abstracts_cache + name + ".json"
     if reload or not os.path.exists(file):
         print(api + name)
         urlretrieve(api_all + name, file)
     # data = codecs.open(file, "r", "utf-8", errors='ignore').read()
     # data = open(file,'rb').read()
     data = open(file).read()
     if not isinstance(data, unicode) and not isinstance(data, str):
         data = data.decode("UTF8", 'ignore')
     # F**K PY3 !!!  'str' object has no attribute 'decode'
     # 	grr PYTHON MADNESS!!
     # http://stackoverflow.com/questions/5096776/unicode-decodeutf-8-ignore-raising-unicodeencodeerror#5096928
     try:
         # data = json.loads(data)
         data = json.loads(data)
     except Exception as ex:
         print(ex)
         os.remove(file)
         # return Node(id=-666, name="ERROR")
     nodes = extensions.xlist()
     # noinspection PyTypeChecker
     for result in data['results']:
         # print(result)
         node = Node(result)
         nodes.append(node)
         if instances:
             nodes.append(self._all(node.id, False, True, reload))
             nodes.append(node.instances)
     self.caches[name] = nodes
     # find_best(nodes)
     return nodes
예제 #10
0
	def map(xs, func):
		return xlist(map(func, xs))
예제 #11
0
	def __sub__(self, other):  # xlist-[1]-[2] minus
		if not hasattr(other, '__iter__'): other = [other]
		return xlist(i for i in self if i not in other)
예제 #12
0
	def unique(xs):
			return xlist(set(xs)) # TypeError: 'NoneType' object is not callable WTF my netbase hack or python bug;)
예제 #13
0
	def where(xs, func):
		return xlist(filter(func, xs))
예제 #14
0
파일: extensions.py 프로젝트: pannous/angle
def grep(xs, x):
	# filter(lambda y: re.match(x,y),xs)
	# return filter(pattern, xs)
	if isinstance(x, list):
		return xlist(filter(lambda y: x[0] in str(y), xs))
	return xlist(filter(lambda y: x in str(y), xs))
예제 #15
0
	def ls(mypath="."):
		return xlist(os.listdir(mypath))
예제 #16
0
파일: extensions.py 프로젝트: pannous/angle
	def c(self):
		return xlist(map(str.c, self).join(", "))  # leave [] which is not compatible with C
예제 #17
0
def ls(mypath="."):
	from extensions import xlist
	return xlist(os.listdir(mypath))
예제 #18
0
파일: extensions.py 프로젝트: pannous/angle
	def __sub__(self, other):  # xlist-[1]-[2] minus
		if not hasattr(other, '__iter__'): other = [other]
		return xlist(i for i in self if i not in other)
예제 #19
0
파일: extensions.py 프로젝트: pannous/angle
	def __rsub__(self, other):  # [1]-xlist-[2] ok!
		return xlist(i for i in other if i not in self)
예제 #20
0
파일: extensions.py 프로젝트: pannous/angle
	def column(xs, n,wtf=0):
		if isinstance(xs[0], str):
			return xlist(map(lambda row: xstr(row).word(n + 1), xs))
		if isinstance(xs[0], list):
			return xlist(map(lambda row: row[n], xs))
		raise Exception("column of %s undefined" % type(xs[0]))
예제 #21
0
파일: extensions.py 프로젝트: pannous/angle
	def map(xs, func):
		return xlist(map(func, xs))
예제 #22
0
파일: extensions.py 프로젝트: pannous/angle
	def like(xs, x):
		return xlist(filter(lambda y: xstr(y).match(x), xs))
예제 #23
0
	def c(self):
		return xlist(map(str.c, self).join(", "))  # leave [] which is not compatible with C
예제 #24
0
	def examples(self):
		return xlist(self.synsets.flatten.map('hyponyms').flatten().map('words').flatten.uniq.map('to_s'))
예제 #25
0
파일: extensions.py 프로젝트: pannous/angle
	def uniq(xs):
		return xlist(set(xs))
예제 #26
0
def ls(mypath="."):
	from extensions import xlist
	return xlist(os.listdir(expanduser(mypath)))
예제 #27
0
파일: extensions.py 프로젝트: pannous/angle
	def wraps(self):
		return xlist(map(lambda x: x.wrap, self).join(", "))  # leave [] which is not compatible with C
예제 #28
0
파일: extensions.py 프로젝트: pannous/angle
	def unique(xs):
			return xlist(set(xs)) # TypeError: 'NoneType' object is not callable WTF my netbase hack or python bug;)
예제 #29
0
def grep(xs, x):
	# filter(lambda y: re.match(x,y),xs)
	# return filter(pattern, xs)
	if isinstance(x, list):
		return xlist(filter(lambda y: x[0] in str(y), xs))
	return xlist(filter(lambda y: x in str(y), xs))
예제 #30
0
파일: extensions.py 프로젝트: pannous/angle
	def values(self):
		return xlist(map(lambda x: x.value, self).join(", "))  # leave [] which is not compatible with C
예제 #31
0
파일: extensions.py 프로젝트: pannous/angle
	def names(self):
		return xlist(map(str, self))
예제 #32
0
파일: extensions.py 프로젝트: pannous/angle
	def item(self, nr):  # -1 AppleScript style !!! BUT list[0] !!!
		return self[xlist(self).fix_int(nr)]
예제 #33
0
	def uniq(xs):
		return xlist(set(xs))
예제 #34
0
파일: extensions.py 프로젝트: pannous/angle
	def word(self, nr):  # -1 AppleScript style !!! BUT list[0] !!!):
		return self[xlist(self).fix_int(nr)]
예제 #35
0
파일: extensions.py 프로젝트: pannous/angle
	def examples(self):
		return xlist(self.synsets.flatten.map('hyponyms').flatten().map('words').flatten.uniq.map('to_s'))
예제 #36
0
	def values(self):
		return xlist(map(lambda x: x.value, self).join(", "))  # leave [] which is not compatible with C
예제 #37
0
	def like(xs, x):
		return xlist(filter(lambda y: xstr(y).match(x), xs))
예제 #38
0
	def item(self, nr):  # -1 AppleScript style !!! BUT list[0] !!!
		return self[xlist(self).fix_int(nr)]
예제 #39
0
	def column(xs, n):
		if isinstance(xs[0], str):
			return xlist(map(lambda row: xstr(row).word(n + 1), xs))
		if isinstance(xs[0], list):
			return xlist(map(lambda row: row[n], xs))
		raise Exception("column of %s undefined" % type(xs[0]))
예제 #40
0
	def select(xs, func):  # VS MAP!!
		return xlist(filter(func, xs))
예제 #41
0
	def __rsub__(self, other):  # [1]-xlist-[2] ok!
		return xlist(i for i in other if i not in self)
예제 #42
0
    'comes after', 'inherits from', 'implements'
    'comes before', 'exact', 'exactly', 'at least', 'at most'
]

logic_operators = [
    "!", "&&", "&", "||", "|", "not", "and", "but", "or", "xor", "nor",
    "neither"
]
math_operators = ["^", "^^", "**", "*", "/", "//", "+", "-", "%"]
english_operators = xlist([
    "power",
    "to the",
    "pow",
    "times",
    "divided by",
    "divide by",
    "plus",
    "minus",
    "add",
    "subtract",
    "mod",
    "modulo",
])

true_operators = math_operators + english_operators + logic_operators  # minus comparison_words

operators = math_operators + english_operators + comparison_words + logic_operators

# todo sorted by decreasing precedence
# DANGER! ambivalent!!   ,"and" 4 and 5 == TROUBLE!!! really? 4 and 5 == 9 ~= True OK lol
# just make sure that 4 and False = False  4 and True == True
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
예제 #43
0
	def wraps(self):
		return xlist(map(lambda x: x.wrap, self).join(", "))  # leave [] which is not compatible with C
예제 #44
0
파일: extensions.py 프로젝트: pannous/angle
	def ls(mypath="."):
		return xlist(os.listdir(mypath))
예제 #45
0
	def names(self):
		return xlist(map(str, self))
예제 #46
0
            'the same']
class_be_words = ['is an', 'is a', ]  # different!

# nicer, sweeter, ....
#  '=>' '<=', DANGER  '¬', not ! alone?  if a¬b: if a ! b    if a not b
# OR class_words
comparison_words = ['be', 'is of', 'is in', 'is a', 'is', 'subset of', 'in', 'are', 'were',
                    '>=', '==', '!=', '¬=', '<=', '=<', '=', '>', '<', '≠', '≤', '≥', '~', '~=', '=~', '~~', '~>',
                    'gt', 'lt', 'identical to', 'smaller or equal', 'greater or equal', 'equal to', 'bigger', 'greater',
                    'eq', 'equals', 'smaller', 'less', 'more', 'the same as', 'same as', 'similar', 'comes after',
                    'inherits from', 'implements''comes before', 'exact', 'exactly',
                    'at least', 'at most']

logic_operators = ["!", "&&", "&", "||", "|", "not", "and", "but", "or", "xor", "nor", "neither"]
math_operators = ["^", "^^", "**", "*", "/", "//", "+", "-", "%"]
english_operators = xlist(["power", "to the", "pow", "times", "divided by", "divide by", "plus", "minus", "add",
                           "subtract", "mod", "modulo", ])

true_operators = math_operators + english_operators + logic_operators  # minus comparison_words

operators = math_operators + english_operators + comparison_words + logic_operators

# todo sorted by decreasing precedence
# DANGER! ambivalent!!   ,"and" 4 and 5 == TROUBLE!!! really? 4 and 5 == 9 ~= True OK lol
# just make sure that 4 and False = False  4 and True == True
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence


once_words = ['whenever', 'wherever', "as soon as", "once"]  # 'on the occasion that',

if_words = ['if']  # , 'in case that', 'provided that', 'assuming that', 'conceding that', 'granted that', \
# 'on the assumption that', 'supposing that', 'with the condition that']
예제 #47
0
	def word(self, nr):  # -1 AppleScript style !!! BUT list[0] !!!):
		return self[xlist(self).fix_int(nr)]
예제 #48
0
	def filter(xs, func):  # VS MAP!!
		# return [x for x in xs if func(x)]
		return xlist(filter(func, xs))