Update rpsystem.py
This commit is contained in:
parent
7568cb29b9
commit
0769ffbef1
1 changed files with 16 additions and 8 deletions
|
|
@ -367,11 +367,12 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
|
||||||
|
|
||||||
# first see if there is a number given (e.g. 1-tall)
|
# first see if there is a number given (e.g. 1-tall)
|
||||||
num_identifier, _ = marker_match.groups("") # return "" if no match, rather than None
|
num_identifier, _ = marker_match.groups("") # return "" if no match, rather than None
|
||||||
istart0 = marker_match.start()
|
match_index = marker_match.start()
|
||||||
istart = istart0 + 1
|
head = string[:match_index]
|
||||||
|
tail = string[match_index+1:]
|
||||||
|
|
||||||
if search_mode:
|
if search_mode:
|
||||||
rquery = "".join([r"\b(" + re.escape(word.strip(punctuation)) + r").*" for word in iter(string[istart:].split())])
|
rquery = "".join([r"\b(" + re.escape(word.strip(punctuation)) + r").*" for word in iter(tail.split())])
|
||||||
rquery = re.compile(rquery, _RE_FLAGS)
|
rquery = re.compile(rquery, _RE_FLAGS)
|
||||||
matches = ((rquery.search(text), obj, text) for obj, text in candidate_map)
|
matches = ((rquery.search(text), obj, text) for obj, text in candidate_map)
|
||||||
bestmatches = [(obj, match.group()) for match, obj, text in matches if match]
|
bestmatches = [(obj, match.group()) for match, obj, text in matches if match]
|
||||||
|
|
@ -379,8 +380,12 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
|
||||||
else:
|
else:
|
||||||
word_list = []
|
word_list = []
|
||||||
bestmatches = []
|
bestmatches = []
|
||||||
for next_word in iter(string[istart:].split()):
|
tail = re.split('(\W)', tail)
|
||||||
word_list.append(next_word.strip(punctuation))
|
istart = 0
|
||||||
|
for i, item in enumerate(tail):
|
||||||
|
if not item.isalpha():
|
||||||
|
continue
|
||||||
|
word_list.append(item)
|
||||||
rquery = "".join([r"\b(" + re.escape(word) + r").*" for word in word_list])
|
rquery = "".join([r"\b(" + re.escape(word) + r").*" for word in word_list])
|
||||||
rquery = re.compile(rquery, _RE_FLAGS)
|
rquery = re.compile(rquery, _RE_FLAGS)
|
||||||
matches = ((rquery.search(text), obj, text) for obj, text in candidate_map)
|
matches = ((rquery.search(text), obj, text) for obj, text in candidate_map)
|
||||||
|
|
@ -390,7 +395,10 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
|
||||||
break
|
break
|
||||||
# set latest match set as best matches
|
# set latest match set as best matches
|
||||||
bestmatches = matches
|
bestmatches = matches
|
||||||
# we have a valid maxscore, extract all matches with this value
|
istart = i
|
||||||
|
|
||||||
|
tail = "".join(tail[istart+1:])
|
||||||
|
|
||||||
nmatches = len(bestmatches)
|
nmatches = len(bestmatches)
|
||||||
|
|
||||||
if not nmatches:
|
if not nmatches:
|
||||||
|
|
@ -441,7 +449,7 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
|
||||||
case = "v"
|
case = "v"
|
||||||
|
|
||||||
key = "#%i%s" % (obj.id, case)
|
key = "#%i%s" % (obj.id, case)
|
||||||
string = string[:istart0] + "{%s}" % key + string[istart + len(match_str) :]
|
string = f"{head}{{{key}}}{tail}"
|
||||||
mapping[key] = obj
|
mapping[key] = obj
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -1109,7 +1117,7 @@ class CmdRecog(RPCommand): # assign personal alias to object in room
|
||||||
if forget_mode:
|
if forget_mode:
|
||||||
# remove existing recog
|
# remove existing recog
|
||||||
caller.recog.remove(obj)
|
caller.recog.remove(obj)
|
||||||
caller.msg("%s will now know them only as '%s'." % (caller.key, obj.recog.get(obj)))
|
caller.msg("%s will now know them only as '%s'." % (caller.key, obj.get_display_name(caller, no_id=True)))
|
||||||
else:
|
else:
|
||||||
# set recog
|
# set recog
|
||||||
sdesc = obj.sdesc.get() if hasattr(obj, "sdesc") else obj.key
|
sdesc = obj.sdesc.get() if hasattr(obj, "sdesc") else obj.key
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue