Пример #1
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)
Пример #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
	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
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
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
	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
	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
	def __rsub__(self, other):  # [1]-xlist-[2] ok!
		return xlist(i for i in other if i not in self)
Пример #20
0
	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
	def map(xs, func):
		return xlist(map(func, xs))
Пример #22
0
	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
	def uniq(xs):
		return xlist(set(xs))
Пример #26
0
def ls(mypath="."):
	from extensions import xlist
	return xlist(os.listdir(expanduser(mypath)))
Пример #27
0
	def wraps(self):
		return xlist(map(lambda x: x.wrap, self).join(", "))  # leave [] which is not compatible with C
Пример #28
0
	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
	def values(self):
		return xlist(map(lambda x: x.value, self).join(", "))  # leave [] which is not compatible with C
Пример #31
0
	def names(self):
		return xlist(map(str, self))
Пример #32
0
	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
	def word(self, nr):  # -1 AppleScript style !!! BUT list[0] !!!):
		return self[xlist(self).fix_int(nr)]
Пример #35
0
	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
	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))