.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.wikidata.WDDateAttribute Class Reference
+ Inheritance diagram for searx.engines.wikidata.WDDateAttribute:
+ Collaboration diagram for searx.engines.wikidata.WDDateAttribute:

Public Member Functions

 get_select (self)
 
 get_where (self)
 
 get_group_by (self)
 
 format_8 (self, value, locale)
 
 format_9 (self, value, locale)
 
 format_10 (self, value, locale)
 
 format_11 (self, value, locale)
 
 format_13 (self, value, locale)
 
 format_14 (self, value, locale)
 
 get_str (self, result, language)
 
- Public Member Functions inherited from searx.engines.wikidata.WDAttribute
 __init__ (self, name)
 
 get_label (self, language)
 
 get_wikibase_label (self)
 
 __repr__ (self)
 

Public Attributes

 name
 
- Public Attributes inherited from searx.engines.wikidata.WDAttribute
 name = name
 

Static Public Attributes

dict DATE_FORMAT
 

Detailed Description

Definition at line 655 of file wikidata.py.

Member Function Documentation

◆ format_10()

searx.engines.wikidata.WDDateAttribute.format_10 ( self,
value,
locale )

Definition at line 690 of file wikidata.py.

690 def format_10(self, value, locale):
691 # precision: month
692 timestamp = isoparse(value)
693 return format_date(timestamp, format='MMMM y', locale=locale)
694

◆ format_11()

searx.engines.wikidata.WDDateAttribute.format_11 ( self,
value,
locale )

Definition at line 695 of file wikidata.py.

695 def format_11(self, value, locale):
696 # precision: day
697 timestamp = isoparse(value)
698 return format_date(timestamp, format='full', locale=locale)
699

◆ format_13()

searx.engines.wikidata.WDDateAttribute.format_13 ( self,
value,
locale )

Definition at line 700 of file wikidata.py.

700 def format_13(self, value, locale):
701 timestamp = isoparse(value)
702 # precision: minute
703 return (
704 get_datetime_format(format, locale=locale)
705 .replace("'", "")
706 .replace('{0}', format_time(timestamp, 'full', tzinfo=None, locale=locale))
707 .replace('{1}', format_date(timestamp, 'short', locale=locale))
708 )
709

◆ format_14()

searx.engines.wikidata.WDDateAttribute.format_14 ( self,
value,
locale )

Definition at line 710 of file wikidata.py.

710 def format_14(self, value, locale):
711 # precision: second.
712 return format_datetime(isoparse(value), format='full', locale=locale)
713

◆ format_8()

searx.engines.wikidata.WDDateAttribute.format_8 ( self,
value,
locale )

Definition at line 676 of file wikidata.py.

676 def format_8(self, value, locale): # pylint: disable=unused-argument
677 # precision: less than a year
678 return value
679

◆ format_9()

searx.engines.wikidata.WDDateAttribute.format_9 ( self,
value,
locale )

Definition at line 680 of file wikidata.py.

680 def format_9(self, value, locale):
681 year = int(value)
682 # precision: year
683 if year < 1584:
684 if year < 0:
685 return str(year - 1)
686 return str(year)
687 timestamp = isoparse(value)
688 return format_date(timestamp, format='yyyy', locale=locale)
689

◆ get_group_by()

searx.engines.wikidata.WDDateAttribute.get_group_by ( self)

Reimplemented from searx.engines.wikidata.WDAttribute.

Definition at line 673 of file wikidata.py.

673 def get_group_by(self):
674 return self.get_select()
675

References searx.engines.wikidata.WDAmountAttribute.get_select(), searx.engines.wikidata.WDArticle.get_select(), searx.engines.wikidata.WDAttribute.get_select(), searx.engines.wikidata.WDDateAttribute.get_select(), searx.engines.wikidata.WDGeoAttribute.get_select(), and searx.engines.wikidata.WDLabelAttribute.get_select().

+ Here is the call graph for this function:

◆ get_select()

searx.engines.wikidata.WDDateAttribute.get_select ( self)

Reimplemented from searx.engines.wikidata.WDAttribute.

Definition at line 656 of file wikidata.py.

656 def get_select(self):
657 return '?{name} ?{name}timePrecision ?{name}timeZone ?{name}timeCalendar'.replace('{name}', self.name)
658

Referenced by searx.engines.wikidata.WDAmountAttribute.get_group_by(), searx.engines.wikidata.WDArticle.get_group_by(), searx.engines.wikidata.WDDateAttribute.get_group_by(), and searx.engines.wikidata.WDGeoAttribute.get_group_by().

+ Here is the caller graph for this function:

◆ get_str()

searx.engines.wikidata.WDDateAttribute.get_str ( self,
result,
language )

Reimplemented from searx.engines.wikidata.WDAttribute.

Definition at line 732 of file wikidata.py.

732 def get_str(self, result, language):
733 value = result.get(self.name)
734 if value == '' or value is None:
735 return None
736 precision = result.get(self.name + 'timePrecision')
737 date_format = WDDateAttribute.DATE_FORMAT.get(precision)
738 if date_format is not None:
739 format_method = getattr(self, date_format[0])
740 precision = date_format[1]
741 try:
742 if precision >= 1:
743 t = value.split('-')
744 if value.startswith('-'):
745 value = '-' + t[1]
746 else:
747 value = t[0]
748 return format_method(value, language)
749 except Exception: # pylint: disable=broad-except
750 return value
751 return value
752
753

References searx.engines.wikidata.WDAmountAttribute.name, searx.engines.wikidata.WDAttribute.name, searx.engines.wikidata.WDDateAttribute.name, searx.engines.wikidata.WDGeoAttribute.name, searx.engines.wikidata.WDLabelAttribute.name, searx.preferences.BooleanChoices.name, and searx.search.models.EngineRef.name.

◆ get_where()

searx.engines.wikidata.WDDateAttribute.get_where ( self)

Reimplemented from searx.engines.wikidata.WDAttribute.

Definition at line 659 of file wikidata.py.

659 def get_where(self):
660 # To remove duplicate, add
661 # FILTER NOT EXISTS { ?item p:{name}/psv:{name}/wikibase:timeValue ?{name}bis FILTER (?{name}bis < ?{name}) }
662 # this filter is too slow, so the response function ignore duplicate results
663 # (see the seen_entities variable)
664 return """OPTIONAL { ?item p:{name}/psv:{name} [
665 wikibase:timeValue ?{name} ;
666 wikibase:timePrecision ?{name}timePrecision ;
667 wikibase:timeTimezone ?{name}timeZone ;
668 wikibase:timeCalendarModel ?{name}timeCalendar ] . }
669 hint:Prior hint:rangeSafe true;""".replace(
670 '{name}', self.name
671 )
672

References searx.engines.wikidata.WDAmountAttribute.name, searx.engines.wikidata.WDAttribute.name, searx.engines.wikidata.WDDateAttribute.name, searx.engines.wikidata.WDGeoAttribute.name, searx.engines.wikidata.WDLabelAttribute.name, searx.preferences.BooleanChoices.name, and searx.search.models.EngineRef.name.

Member Data Documentation

◆ DATE_FORMAT

dict searx.engines.wikidata.WDDateAttribute.DATE_FORMAT
static
Initial value:
= {
'0': ('format_8', 1000000000),
'1': ('format_8', 100000000),
'2': ('format_8', 10000000),
'3': ('format_8', 1000000),
'4': ('format_8', 100000),
'5': ('format_8', 10000),
'6': ('format_8', 1000),
'7': ('format_8', 100),
'8': ('format_8', 10),
'9': ('format_9', 1), # year
'10': ('format_10', 1), # month
'11': ('format_11', 0), # day
'12': ('format_13', 0), # hour (not supported by babel, display minute)
'13': ('format_13', 0), # minute
'14': ('format_14', 0), # second
}

Definition at line 714 of file wikidata.py.

◆ name


The documentation for this class was generated from the following file: