コード例 #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
ファイル: power_parser.py プロジェクト: cppxaxa/angle
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
ファイル: power_parser.py プロジェクト: pannous/angle
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
ファイル: extensions.py プロジェクト: pannous/hieros
	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
ファイル: extension_functions.py プロジェクト: pannous/angle
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
ファイル: extensions.py プロジェクト: pannous/hieros
	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
ファイル: english_tokens.py プロジェクト: pannous/angle
            '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
ファイル: extensions.py プロジェクト: pannous/hieros
	def filter(xs, func):  # VS MAP!!
		# return [x for x in xs if func(x)]
		return xlist(filter(func, xs))