本文整理汇总了Python中s3.s3utils.soundex函数的典型用法代码示例。如果您正苦于以下问题:Python soundex函数的具体用法?Python soundex怎么用?Python soundex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了soundex函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _parse_keywords
def _parse_keywords(message_body):
"""
Parse Keywords
- helper function for search_resource, etc
"""
# Equivalent keywords in one list
primary_keywords = ["get", "give", "show"]
contact_keywords = ["email", "mobile", "facility", "clinical",
"security", "phone", "status", "hospital",
"person", "organisation"]
pkeywords = primary_keywords + contact_keywords
keywords = message_body.split(" ")
pquery = []
name = ""
for word in keywords:
match = None
for key in pkeywords:
if soundex(key) == soundex(word):
match = key
break
if match:
pquery.append(match)
else:
name = word
return pquery, name
开发者ID:flavour,项目名称:aidiq,代码行数:28,代码来源:parser.py
示例2: search_organisation
def search_organisation(self, message, pquery=None, name=None):
"""
Search for Organisations
- can be called direct
- can be called from search_by_keyword
"""
message_body = message.body
if not message_body:
return None
if not pquery or not name:
pquery, name = self._parse_keywords(message_body)
T = current.T
db = current.db
s3db = current.s3db
reply = None
result = []
# Organization search [example: get name organisation phone]
s3_accessible_query = current.auth.s3_accessible_query
table = s3db.org_organisation
query = (table.deleted == False) & \
(s3_accessible_query("read", table))
rows = db(query).select(table.id,
table.name,
table.phone,
table.acronym)
_name = soundex(str(name))
for row in rows:
if (_name == soundex(row.name)) or \
(_name == soundex(row.acronym)):
result.append(row)
if len(reply) == 0:
return T("No Match")
elif len(result) > 1:
return T("Multiple Matches")
else:
# Single Match
org = result[0]
reply = "%s %s (%s) " % (reply, org.name,
T("Organization"))
if "phone" in pquery:
reply = reply + "Phone->" + str(org.phone)
if "office" in pquery:
otable = s3db.org_office
query = (otable.organisation_id == org.id) & \
(s3_accessible_query("read", otable))
office = db(query).select(otable.address,
limitby=(0, 1)).first()
reply = reply + "Address->" + office.address
return reply
开发者ID:flavour,项目名称:aidiq,代码行数:58,代码来源:parser.py
示例3: parse_hospital
def parse_hospital(self, pquery="", name="", sender=""):
"""
Search for Hospitals
"""
T = current.T
db = current.db
s3db = current.s3db
result = []
reply = ""
# Hospital Search [example: get name hospital facility status ]
table = s3db.hms_hospital
stable = s3db.hms_status
query = (table.deleted == False) & \
(current.auth.s3_accessible_query("read", table))
rows = db(query).select(table.id,
table.name,
table.aka1,
table.aka2,
table.phone_emergency
)
_name = soundex(str(name))
for row in rows:
if (_name == soundex(row.name)) or \
(_name == soundex(row.aka1)) or \
(_name == soundex(row.aka2)):
result.append(row)
if len(result) > 1:
return T("Multiple Matches")
if len(result) == 1:
hospital = result[0]
status = db(stable.hospital_id == hospital.id).\
select(limitby=(0,1)).first()
reply = "%s %s (%s) " % (reply, hospital.name,
T("Hospital"))
if "phone" in pquery:
reply = reply + "Phone->" + str(hospital.phone_emergency)
if "facility" in pquery:
reply = reply + "Facility status " + \
str(stable.facility_status.represent\
(status.facility_status))
if "clinical" in pquery:
reply = reply + "Clinical status " + \
str(stable.clinical_status.represent\
(status.clinical_status))
if "security" in pquery:
reply = reply + "Security status " + \
str(stable.security_status.represent\
(status.security_status))
if len(result) == 0:
return T("No Match")
return reply
开发者ID:awriel,项目名称:eden,代码行数:58,代码来源:parser.py
示例4: search_hospital
def search_hospital(self, message, pquery=None, name=None):
"""
Search for Hospitals
- can be called direct
- can be called from search_by_keyword
"""
message_body = message.body
if not message_body:
return None
if not pquery or not name:
pquery, name = self._parse_keywords(message_body)
T = current.T
db = current.db
s3db = current.s3db
reply = None
result = []
# Hospital Search [example: get name hospital facility status ]
table = s3db.hms_hospital
stable = s3db.hms_status
query = (table.deleted == False) & (current.auth.s3_accessible_query("read", table))
rows = db(query).select(table.id, table.name, table.aka1, table.aka2, table.phone_emergency)
_name = soundex(str(name))
for row in rows:
if (_name == soundex(row.name)) or (_name == soundex(row.aka1)) or (_name == soundex(row.aka2)):
result.append(row)
if len(result) == 0:
return T("No Match")
elif len(result) > 1:
return T("Multiple Matches")
else:
# Single Match
hospital = result[0]
status = (
db(stable.hospital_id == hospital.id)
.select(stable.facility_status, stable.clinical_status, stable.security_status, limitby=(0, 1))
.first()
)
reply = "%s %s (%s) " % (reply, hospital.name, T("Hospital"))
if "phone" in pquery:
reply = reply + "Phone->" + str(hospital.phone_emergency)
if "facility" in pquery:
reply = reply + "Facility status " + str(stable.facility_status.represent(status.facility_status))
if "clinical" in pquery:
reply = reply + "Clinical status " + str(stable.clinical_status.represent(status.clinical_status))
if "security" in pquery:
reply = reply + "Security status " + str(stable.security_status.represent(status.security_status))
return reply
开发者ID:redhumus,项目名称:eden,代码行数:56,代码来源:parser.py
示例5: parse_org
def parse_org(self, pquery="", name="", sender=""):
"""
Search for Organisations
"""
T = current.T
db = current.db
s3db = current.s3db
result = []
reply = ""
# Organization search [example: get name organisation phone]
s3_accessible_query = current.auth.s3_accessible_query
table = s3db.org_organisation
query = (table.deleted == False) & \
(s3_accessible_query("read", table))
rows = db(query).select(table.id,
table.name,
table.donation_phone,
table.acronym)
_name = soundex(str(name))
for row in rows:
if (_name == soundex(row.name)) or \
(_name == soundex(row.acronym)):
result.append(row)
if len(reply) == 0:
return T("No Match")
elif len(result) > 1:
return T("Multiple Matches")
else:
# Single Match
org = result[0]
reply = "%s %s (%s) " % (reply, org.name,
T("Organization"))
if "phone" in pquery:
reply = reply + "Phone->" + str(org.donation_phone)
if "office" in pquery:
otable = s3db.org_office
query = (otable.organisation_id == org.id) & \
(s3_accessible_query("read", otable))
office = db(query).select(otable.address,
limitby=(0, 1)).first()
reply = reply + "Address->" + office.address
return reply
开发者ID:MePiyush,项目名称:eden,代码行数:49,代码来源:parser.py
示例6: keyword_search
def keyword_search(message="", sender=""):
"""
1st Pass Parser for searching people,
hospitals and organisations.
"""
if not message:
return None
T = current.T
db = current.db
s3db = current.s3db
# Equivalent keywords in one list
primary_keywords = ["get", "give", "show"]
contact_keywords = ["email", "mobile", "facility", "clinical",
"security", "phone", "status", "hospital",
"person", "organisation"]
pkeywords = primary_keywords + contact_keywords
keywords = string.split(message)
pquery = []
name = ""
reply = ""
for word in keywords:
match = None
for key in pkeywords:
if soundex(key) == soundex(word):
match = key
break
if match:
pquery.append(match)
else:
name = word
parser = S3Parsing()
if "person" in pquery:
reply = parser.parse_person(pquery, name, sender)
elif "hospital" in pquery:
reply = parser.parse_hospital(pquery, name, sender)
elif "organisation" in pquery:
reply = parser.parse_org(pquery, name, sender)
else:
reply = False
return reply
开发者ID:awriel,项目名称:eden,代码行数:45,代码来源:parser.py
示例7: parse_ireport
def parse_ireport(message="", sender=""):
"""
Parse Messages directed to the IRS Module.
"""
if not message:
return None
T = current.T
db = current.db
s3db = current.s3db
msg = current.msg
parser = S3Parsing()
(lat, lon, code, text) = msg.parse_opengeosms(message)
if code == "SI":
reply = parser.parse_opengeosms(lat, lon, text, message, sender)
else:
words = string.split(message)
message = ""
reponse = ""
ireport = False
comments = False
for word in words:
if "SI#" in word and not ireport:
report = word.split("#")[1]
report = int(report)
ireport = True
elif (soundex(word) == soundex("Yes")) and ireport \
and not comments:
response = True
comments = True
elif soundex(word) == soundex("No") and ireport \
and not comments:
response = False
comments = True
elif comments:
message += word + " "
if ireport:
reply = parser.parse_drequest(report, response, message, sender)
else:
reply = False
return reply
开发者ID:awriel,项目名称:eden,代码行数:45,代码来源:parser.py
示例8: parse_ireport
def parse_ireport(self, message):
"""
Parse Messages directed to the IRS Module
- logging new incidents
- responses to deployment requests
"""
message_body = message.body
if not message_body:
return None
(lat, lon, code, text) = current.msg.parse_opengeosms(message_body)
if code == "SI":
# Create New Incident Report
reply = self._create_ireport(lat, lon, text)
else:
# Is this a Response to a Deployment Request?
words = message_body.split(" ")
text = ""
reponse = ""
report_id = None
comments = False
for word in words:
if "SI#" in word and not ireport:
report = word.split("#")[1]
report_id = int(report)
elif (soundex(word) == soundex("Yes")) and report_id \
and not comments:
response = True
comments = True
elif soundex(word) == soundex("No") and report_id \
and not comments:
response = False
comments = True
elif comments:
text += word + " "
if report_id:
reply = self._respond_drequest(message, report_id, response, text)
else:
reply = None
return reply
开发者ID:flavour,项目名称:aidiq,代码行数:44,代码来源:parser.py
示例9: search_person
def search_person(self, message, pquery=None, name=None):
"""
Search for People
- can be called direct
- can be called from search_by_keyword
"""
message_body = message.body
if not message_body:
return None
if not pquery or not name:
pquery, name = self._parse_keywords(message_body)
T = current.T
db = current.db
s3db = current.s3db
reply = None
result = []
# Person Search [get name person phone email]
s3_accessible_query = current.auth.s3_accessible_query
table = s3db.pr_person
query = (table.deleted == False) & \
(s3_accessible_query("read", table))
rows = db(query).select(table.pe_id,
table.first_name,
table.middle_name,
table.last_name)
_name = soundex(str(name))
for row in rows:
if (_name == soundex(row.first_name)) or \
(_name == soundex(row.middle_name)) or \
(_name == soundex(row.last_name)):
presult = dict(name = row.first_name, id = row.pe_id)
result.append(presult)
if len(result) == 0:
return T("No Match")
elif len(result) > 1:
return T("Multiple Matches")
else:
# Single Match
reply = result[0]["name"]
table = s3db.pr_contact
if "email" in pquery:
query = (table.pe_id == result[0]["id"]) & \
(table.contact_method == "EMAIL") & \
(s3_accessible_query("read", table))
recipient = db(query).select(table.value,
orderby = table.priority,
limitby=(0, 1)).first()
if recipient:
reply = "%s Email->%s" % (reply, recipient.value)
else:
reply = "%s 's Email Not available!" % reply
if "phone" in pquery:
query = (table.pe_id == result[0]["id"]) & \
(table.contact_method == "SMS") & \
(s3_accessible_query("read", table))
recipient = db(query).select(table.value,
orderby = table.priority,
limitby=(0, 1)).first()
if recipient:
reply = "%s Mobile->%s" % (reply,
recipient.value)
else:
reply = "%s 's Mobile Contact Not available!" % reply
return reply
开发者ID:flavour,项目名称:aidiq,代码行数:73,代码来源:parser.py
示例10: parse_person
def parse_person(self, pquery="", name="", sender=""):
"""
Search for People
"""
T = current.T
db = current.db
s3db = current.s3db
result = []
reply = ""
# Person Search [get name person phone email]
s3_accessible_query = current.auth.s3_accessible_query
table = s3db.pr_person
query = (table.deleted == False) & \
(s3_accessible_query("read", table))
rows = db(query).select(table.pe_id,
table.first_name,
table.middle_name,
table.last_name)
_name = soundex(str(name))
for row in rows:
if (_name == soundex(row.first_name)) or \
(_name == soundex(row.middle_name)) or \
(_name == soundex(row.last_name)):
presult = dict(name = row.first_name, id = row.pe_id)
result.append(presult)
if len(result) > 1:
return T("Multiple Matches")
if len(result) == 1:
reply = result[0]["name"]
table = s3db.pr_contact
if "email" in pquery:
query = (table.pe_id == result[0]["id"]) & \
(table.contact_method == "EMAIL") & \
(s3_accessible_query("read", table))
recipient = db(query).select(table.value,
orderby = table.priority,
limitby=(0, 1)).first()
if recipient:
reply = "%s Email->%s" % (reply, recipient.value)
else:
reply = "%s 's Email Not available!"%reply
if "phone" in pquery:
query = (table.pe_id == result[0]["id"]) & \
(table.contact_method == "SMS") & \
(s3_accessible_query("read", table))
recipient = db(query).select(table.value,
orderby = table.priority,
limitby=(0, 1)).first()
if recipient:
reply = "%s Mobile->%s" % (reply,
recipient.value)
else:
reply = "%s 's Mobile Contact Not available!"%reply
if len(result) == 0:
return T("No Match")
return reply
开发者ID:awriel,项目名称:eden,代码行数:62,代码来源:parser.py
示例11: parse_1
def parse_1(message=""):
"""
Parsing Workflow 1.
"""
if not message:
return None
T = current.T
db = current.db
s3db = current.s3db
s3mgr = current.manager
primary_keywords = ["get", "give", "show"] # Equivalent keywords in one list
contact_keywords = ["email", "mobile", "facility", "clinical",
"security", "phone", "status", "hospital",
"person", "organisation"]
pkeywords = primary_keywords+contact_keywords
keywords = string.split(message)
pquery = []
name = ""
reply = ""
for word in keywords:
match = None
for key in pkeywords:
if soundex(key) == soundex(word):
match = key
break
if match:
pquery.append(match)
else:
name = word
# ---------------------------------------------------------------------
# Person Search [get name person phone email]
if "person" in pquery:
table = s3db.pr_person
rows = db(table.id > 0).select(table.pe_id,
table.first_name,
table.middle_name,
table.last_name)
for row in rows:
result = []
if (soundex(str(name)) == soundex(str(row.first_name))) or \
(soundex(str(name)) == soundex(str(row.middle_name))) or \
(soundex(str(name)) == soundex(str(row.last_name))):
presult = dict(name = row.first_name, id = row.pe_id)
result.append(presult)
break
if len(result) > 1:
return T("Multiple Matches")
if len(result) == 1:
reply = result[0]["name"]
table = s3db.pr_contact
if "email" in pquery:
query = (table.pe_id == result[0]["id"]) & \
(table.contact_method == "EMAIL")
recipient = db(query).select(table.value,
orderby = table.priority,
limitby=(0, 1)).first()
reply = "%s Email->%s" % (reply, recipient.value)
if "phone" in pquery:
query = (table.pe_id == result[0]["id"]) & \
(table.contact_method == "SMS")
recipient = db(query).select(table.value,
orderby = table.priority,
limitby=(0, 1)).first()
reply = "%s Mobile->%s" % (reply,
recipient.value)
if len(result) == 0:
return T("No Match")
return reply
return "Please provide one of the keywords - person, hospital, organisation"
开发者ID:shashi,项目名称:eden,代码行数:79,代码来源:parser.py
示例12: parse_3
def parse_3(message=""):
"""
Parsing Workflow 3.
"""
if not message:
return None
T = current.T
db = current.db
s3db = current.s3db
s3mgr = current.manager
primary_keywords = ["get", "give", "show"] # Equivalent keywords in one list
contact_keywords = ["email", "mobile", "facility", "clinical",
"security", "phone", "status", "hospital",
"person", "organisation"]
pkeywords = primary_keywords+contact_keywords
keywords = string.split(message)
pquery = []
name = ""
reply = ""
for word in keywords:
match = None
for key in pkeywords:
if soundex(key) == soundex(word):
match = key
break
if match:
pquery.append(match)
else:
name = word
# ---------------------------------------------------------------------
# Organization search [example: get name organisation phone]
if "organisation" in pquery:
table = s3db.org_organisation
rows = db(table.id > 0).select(table.id,
table.name,
table.acronym)
for row in rows:
result = []
if (soundex(str(name)) == soundex(str(row.name))) or \
(soundex(str(name)) == soundex(str(row.acronym))):
result.append(row)
break
if len(result) > 1:
return T("Multiple Matches")
if len(result) == 1:
organisation = db(table.id == result[0].id).select().first()
reply = "%s %s (%s) " % (reply, organisation.name,
T("Organization"))
if "phone" in pquery:
reply = reply + "Phone->" + str(organisation.donation_phone)
if "office" in pquery:
reply = reply + "Address->" + s3_get_db_field_value(tablename = "org_office",
fieldname = "address",
look_up_value = organisation.id)
if len(reply) == 0:
return T("No Match")
return reply
return "Please provide one of the keywords - person, hospital, organisation"
开发者ID:shashi,项目名称:eden,代码行数:66,代码来源:parser.py
示例13: parse_2
def parse_2(message=""):
"""
Parsing Workflow 2.
"""
if not message:
return None
T = current.T
db = current.db
s3db = current.s3db
s3mgr = current.manager
primary_keywords = ["get", "give", "show"] # Equivalent keywords in one list
contact_keywords = ["email", "mobile", "facility", "clinical",
"security", "phone", "status", "hospital",
"person", "organisation"]
pkeywords = primary_keywords+contact_keywords
keywords = string.split(message)
pquery = []
name = ""
reply = ""
for word in keywords:
match = None
for key in pkeywords:
if soundex(key) == soundex(word):
match = key
break
if match:
pquery.append(match)
else:
name = word
# ---------------------------------------------------------------------
# Hospital Search [example: get name hospital facility status ]
if "hospital" in pquery:
table = s3db.hms_hospital
rows = db(table.id > 0).select(table.id,
table.name,
table.aka1,
table.aka2)
for row in rows:
result = []
if (soundex(str(name)) == soundex(str(row.name))) or \
(soundex(name) == soundex(str(row.aka1))) or \
(soundex(name) == soundex(str(row.aka2))):
result.append(row)
break
if len(result) > 1:
return T("Multiple Matches")
if len(result) == 1:
hospital = db(table.id == result[0].id).select().first()
reply = "%s %s (%s) " % (reply, hospital.name,
T("Hospital"))
if "phone" in pquery:
reply = reply + "Phone->" + str(hospital.phone_emergency)
if "facility" in pquery:
reply = reply + "Facility status " + str(table.facility_status.represent(hospital.facility_status))
if "clinical" in pquery:
reply = reply + "Clinical status " + str(table.clinical_status.represent(hospital.clinical_status))
if "security" in pquery:
reply = reply + "Security status " + str(table.security_status.represent(hospital.security_status))
if len(result) == 0:
return T("No Match")
return reply
return "Please provide one of the keywords - person, hospital, organisation"
开发者ID:shashi,项目名称:eden,代码行数:72,代码来源:parser.py
注:本文中的s3.s3utils.soundex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论