team4alfanous team mailing list archive
-
team4alfanous team
-
Mailing list archive
-
Message #00324
[Branch ~team4alfanous/alfanous/alfanous-git] Rev 512: add a new flag "unit" to distinguish between search in Ayahs, Quranic
------------------------------------------------------------
revno: 512
committer: Assem Chelli <assem.ch@xxxxxxxxx>
timestamp: Sun 2013-01-06 18:22:27 +0100
message:
add a new flag "unit" to distinguish between search in Ayahs, Quranic
translations and Quranic Words
modified:
src/alfanous/Outputs.py
src/alfanous/README.rst
src/alfanous/console.py
--
lp:alfanous
https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git
Your team Alfanous team is subscribed to branch lp:alfanous.
To unsubscribe from this branch go to https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git/+edit-subscription
=== modified file 'src/alfanous/Outputs.py'
--- src/alfanous/Outputs.py 2013-01-05 21:01:22 +0000
+++ src/alfanous/Outputs.py 2013-01-06 17:22:27 +0000
@@ -99,6 +99,7 @@
"results_limit":6236,
"flags":{
"action":"search",
+ "unit":"aya",
"ident":"undefined",
"platform":"undefined",
"domain":"undefined",
@@ -143,6 +144,7 @@
DOMAINS = {
"action": ["search", "suggest", "show"],
+ "unit": ["aya", "word", "translation"],
"ident":["undefined"],
"platform":["undefined", "wp7", "s60", "android", "ios", "linux", "window"],
"domain":[],
@@ -176,6 +178,7 @@
HELPMESSAGES = {
"action": "action to perform",
+ "unit": "search unit",
"ident":"identifier of requester",
"platform":"platform used by requester",
"domain":"web domain of requester if applicable",
@@ -234,6 +237,7 @@
self._information = Resources.information( Information_file )
##
self._stats = Configs.stats( Stats_file )
+ # enable it if you need statistics , disable it you prefer performance
self._init_stats()
##
self._surates = [item for item in self.QSE.list_values( "sura" ) if item]
@@ -270,10 +274,13 @@
def _do( self, flags ):
#try:
action = flags["action"] if flags.has_key( "action" ) else self._defaults["flags"]["action"]
+ unit = flags["unit"] if flags.has_key( "unit" ) else self._defaults["flags"]["unit"]
ident = flags["ident"] if flags.has_key( "ident" ) else self._defaults["flags"]["ident"]
platform = flags["platform"] if flags.has_key( "platform" ) else self._defaults["flags"]["platform"]
domain = flags["domain"] if flags.has_key( "domain" ) else self._defaults["flags"]["domain"]
- # gather statistics
+
+ # gather statistics, enable it if you need use statistics
+ # disable it if you prefer performance
self._process_stats( flags )
# init the error message with Succes
@@ -282,9 +289,9 @@
if SCAN_SUPERJOKERS( flags["query"] ): #Quick fix!!
output = self._check( 2, flags )
else:
- output.update( self._search( flags ) )
+ output.update( self._search( flags, unit ) )
elif action == "suggest":
- output.update( self._suggest( flags ) )
+ output.update( self._suggest( flags, unit ) )
elif action == "show":
output.update( self._show( flags ) )
else:
@@ -358,8 +365,18 @@
else:
return {"show":None}
- def _suggest( self, flags ):
- """ return suggestions """
+ def _suggest( self, flags, unit ):
+ """ return suggestions for any search unit """
+ if unit == "aya":
+ suggestions = self._suggest_aya( flags )
+ else:
+ suggestions = {}
+
+ return {"suggest": suggestions}
+
+
+ def _suggest_aya( self, flags ):
+ """ return suggestions for aya words """
query = flags["query"] if flags.has_key( "query" ) else self._defaults["flags"]["query"]
#preprocess query
query = query.replace( "\\", "" )
@@ -370,11 +387,20 @@
except Exception:
output = {}
- return {"suggest":output}
-
- def _search( self, flags ):
+ return output
+
+ def _search( self, flags, unit ):
+ """ return the results of search for any unit """
+ if unit == "aya":
+ search_results = self._search_aya( flags )
+ else:
+ search_results = {}
+
+ return { "search": search_results }
+
+ def _search_aya( self, flags ):
"""
- return the results of search as json
+ return the results of aya search as a dictionary data structure
"""
#flags
query = flags["query"] if flags.has_key( "query" ) \
@@ -727,8 +753,7 @@
"annotations": {} if not annotation_aya or not annotations_by_position.has_key( ( r["sura_id"], r["aya_id"] ) )
else annotations_by_position[( r["sura_id"], r["aya_id"] )]
}
- return {"search": output}
-
+ return output
class Json( Raw ):
@@ -742,52 +767,7 @@
@deprecated: Why Xml and CompleXity?! Use jSon and Simplicity!
"""
- def suggest( self, query ):
- """ return suggestions """
- raw_output = super( Json, self ).suggest( query )
- xml_output = "\n".join(
- [
- '<word text="%(word)s"> %(suggestions)s </word>' % {
- "word":word,
- "suggestions": "\n".join( ['<suggestion text="%s"/>' % suggestion for suggestion in raw_output[word]] )
- }
- for word in raw_output.keys()
- ]
- )
- return xml_output
-
- def search( self, query, sortedby = "score", offset = 1, range = 10 ):
- """ return results """
- #TODO: complete it manually or using an Python2XML dump , JSON2XML,or manually
- schema = """
- <results runtime=%(runtime)f > # output["runtime"
- <words nb_words=%(nb_words) global_nb_matches=%(global_nb_matches)>
- <word cpt="%cpt" text="%word" nb_matches=%(nb_matches) nb_ayas=%(nb_ayas) > * cpt
-
- </words>
- <ayas total="%total" start="%start" end="%end">
- <aya cpt=%cpt>
- <aya_info id=%id>
-
- <text> </text>
- <text>
-
-
- </aya_info>
-
-
-
-
- </aya>
-
-
-
-
- </ayas>
- </results>
-
- """
- return None
+ pass
=== modified file 'src/alfanous/README.rst'
--- src/alfanous/README.rst 2013-01-05 19:09:10 +0000
+++ src/alfanous/README.rst 2013-01-06 17:22:27 +0000
@@ -112,45 +112,47 @@
Flags
--------------
-======== =================== ================= ============================================ ================= ========================================================================================================================================================================
- number flag related action description default value accepted values
--------- ------------------- ----------------- -------------------------------------------- ----------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- 1 **action** <none> action to perform "error" search | suggest | show
- 2 ident <all> identifier of requester [experimental] "undefined" undefined
- 3 platform <all> platform used by requester "undefined" undefined | wp7 | s60 | android | ios | linux | window
- 4 domain <all> web domain of requester if applicable "undefined" \*
- 5a **query** search,suggest query attached to action "" \*
- 5b **query** show query attached to action "" all | translations |recitations | information | hints | surates | chapters | defaults | flags | fields | fields_reverse | errors | domains | help_messages
- 6 highlight search highlight method "css" css | html | genshi | bold | bbcode
- 7 script search script of aya text "standard" standard | uthmani
- 8 vocalized search enable vocalization of aya text "True" True | False
- 9 recitation search recitation id "1" 1 to 30
- 10 translation search translation id "None" \*
- 11 romanization search type of romanization "none" none | buckwalter | iso | arabtex
- 11 view search pre-defined configuration for view "custom" minimal | normal | full | statistic | linguistic | custom
- 12 prev_aya search enable previous aya retrieving "False" True | False
- 13 next_aya search enable next aya retrieving "False" True | False
- 14 sura_info search enable sura information retrieving "True" True | False
- 15 sura_stat_info search enable sura stats retrieving "False" True | False
- 16 word_info search enable word information retrieving "True" True | False
- 17 aya_position_info search enable aya position information retrieving "True" True | False
- 18 aya_theme_info search enable aya theme information retrieving "True" True | False
- 19 aya_stat_info search enable aya stat information retrieving "True" True | False
- 20 aya_sajda_info search enable aya sajda information retrieving "True" True | False
- 21 annotation_word search enable query terms annotations retrieving "False" True | False
- 22 annotation_aya search enable aya words annotations retrieving "False" True | False
- 23 sortedby search sorting order of results "score" total | score | mushaf | tanzil | subject
- 24 offset search starting offset of results "1" 1 to 6236
- 25 range search range of results "10" 1 to 25
- 26 page search page number [override offset] "1" 1 to 6236
- 27 perpage search results per page [override range] "10" 1 to 25
- 28 fuzzy search fuzzy search [exprimental] "False" True | False
+======== =================== ================= ================ ============================================ ================= ========================================================================================================================================================================
+ number flag related action related unit description default value accepted values
+-------- ------------------- ----------------- ---------------- ---------------------------- ----------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ 1 **action** <none> <none> action to perform "search" search | suggest | show
+ 2 unit search, suggest <none> search unit "aya" aya | word | translation
+ 2 ident <all> <all> identifier of requester [experimental] "undefined" undefined
+ 3 platform <all> <all> platform used by requester "undefined" undefined | wp7 | s60 | android | ios | linux | window
+ 4 domain <all> <all> web domain of requester if applicable "undefined" \*
+ 5a **query** search,suggest <all> query attached to action "" \*
+ 5b **query** show <all> query attached to action "" all | translations |recitations | information | hints | surates | chapters | defaults | flags | fields | fields_reverse | errors | domains | help_messages
+ 6 highlight search <all> highlight method "css" css | html | genshi | bold | bbcode
+ 7 script search aya, word script of aya text "standard" standard | uthmani
+ 8 vocalized search aya, word enable vocalization of aya text "True" True | False
+ 9 recitation search aya recitation id "1" 1 to 30
+ 10 translation search aya, trans translation id "None" \*
+ 11 romanization search aya, word type of romanization "none" none | buckwalter | iso | arabtex
+ 11 view search <all> pre-defined configuration for view "custom" minimal | normal | full | statistic | linguistic | custom
+ 12 prev_aya search aya enable previous aya retrieving "False" True | False
+ 13 next_aya search aya enable next aya retrieving "False" True | False
+ 14 sura_info search aya enable sura information retrieving "True" True | False
+ 15 sura_stat_info search aya enable sura stats retrieving "False" True | False
+ 16 word_info search aya, word enable word information retrieving "True" True | False
+ 17 aya_position_info search aya enable aya position information retrieving "True" True | False
+ 18 aya_theme_info search aya enable aya theme information retrieving "True" True | False
+ 19 aya_stat_info search aya enable aya stat information retrieving "True" True | False
+ 20 aya_sajda_info search aya enable aya sajda information retrieving "True" True | False
+ 21 annotation_word search aya, word enable query terms annotations retrieving "False" True | False
+ 22 annotation_aya search aya enable aya words annotations retrieving "False" True | False
+ 23 sortedby search <all> sorting order of results "score" total | score | mushaf | tanzil | subject
+ 24 offset search <all> starting offset of results "1" 1 to 6236
+ 25 range search <all> range of results "10" 1 to 25
+ 26 page search <all> page number [override offset] "1" 1 to 6236
+ 27 perpage search <all> results per page [override range] "10" 1 to 25
+ 28 fuzzy search aya fuzzy search [exprimental] "False" True | False
======== =================== ================= ============================================ ================= ========================================================================================================================================================================
-----------------------
Advanced Query Examples
-----------------------
+Aya Search:
* Simple search: الحمد
* Phrases : "الحمد لله"
* Logical relations - ANDNOT : (الصلاة - الزكاة)
@@ -170,7 +172,7 @@
------
Fields
------
-
+* Aya Search Fields:
===== ================= =================== ============== ============================================================
n عربي English Values Description
----- ----------------- ------------------- -------------- ------------------------------------------------------------
@@ -212,7 +214,7 @@
----------------
SortedBy Options
----------------
-
+* Aya Search:
========== =================================================================================
Option Description
---------- ---------------------------------------------------------------------------------
@@ -220,6 +222,7 @@
mushaf The default order of ayas in Mus-haf
tanzil The revelation order
subject The alphabetic order of the values for subjects fields
+ ayalenght The length of ayah from the shortest to the longest
FIELD The numerical order or alphabetic order of a costum field (see Fields_ )
========== =================================================================================
@@ -228,7 +231,7 @@
==============
Schema Samples
==============
-
+* Aya Search:
-----------
Suggestions
-----------
=== modified file 'src/alfanous/console.py'
--- src/alfanous/console.py 2013-01-01 12:09:11 +0000
+++ src/alfanous/console.py 2013-01-06 17:22:27 +0000
@@ -42,6 +42,7 @@
# add arguments
arg_parser.add_argument( "-a", "--action", dest = "action", type = str , choices = DOMAINS["action"], help = HELPMESSAGES["action"] )
+arg_parser.add_argument( "-u", "--unit", dest = "unit", type = str , choices = DOMAINS["unit"], help = HELPMESSAGES["unit"] )
arg_parser.add_argument( "-q", "--query", dest = "query", type = str , help = HELPMESSAGES["query"] )
arg_parser.add_argument( "-o", "--offset", dest = "offset", metavar = 'NUMBER', type = int, help = HELPMESSAGES["offset"] )
arg_parser.add_argument( "-r", "--range", dest = "range", type = int, metavar = 'NUMBER', help = HELPMESSAGES["range"] )
@@ -51,6 +52,7 @@
arg_parser.add_argument( "--perpage", dest = "perpage", type = int, metavar = 'NUMBER', help = HELPMESSAGES["perpage"] )
arg_parser.add_argument( "--recitation", dest = "recitation", metavar = 'NUMBER', type = str, help = HELPMESSAGES["recitation"] )
arg_parser.add_argument( "--translation", dest = "translation", type = str, help = HELPMESSAGES["translation"] )
+arg_parser.add_argument( "--romanization", dest = "romanization", type = str, help = HELPMESSAGES["romanization"] )
arg_parser.add_argument( "--highlight", dest = "highlight", type = str, choices = DOMAINS["highlight"], help = HELPMESSAGES["highlight"] )
arg_parser.add_argument( "--script", dest = "script", type = str, choices = DOMAINS["script"] , help = HELPMESSAGES["script"] )
arg_parser.add_argument( "--vocalized", dest = "vocalized", type = bool, choices = DOMAINS["vocalized"], help = HELPMESSAGES["vocalized"] )