示例#1
0
  def search(self, query: str, **opt) -> List[Score]:
    """
    Performs a recommendation-based search.
    Returns an array of score objects, containing the
    relevant pages and their associated scores.
    """
    scores = []
    queryWords = self.__parse_query_string(query)

    for page in self.__pages:
      # create and calculate scores
      pageScore = Score(page)
      wordFreq = self.__metrics.get_word_frequency_score(page, queryWords)
      docLoc = self.__metrics.get_document_location_score(page, queryWords)
      
      pageScore.set_content_score(wordFreq)
      pageScore.set_location_score(docLoc)
      scores.append(pageScore)

    # normalize scores
    self.__metrics.normalize_scores(scores)

    # generate results
    relevantScores = list(filter(lambda x : x.get_content_score() > 0, scores))

    # sort list
    relevantScores.sort(key=lambda x : x.get_weighted_score(), reverse=True)
    
    if COUNT_ID in opt:
      return relevantScores[0:opt[COUNT_ID]]
    else:
      return relevantScores
示例#2
0
 def setSMOG(self, smog: float) -> None:
     """
     Set the SMOG Score
     :param smog: Set the SMOG Score
     :return: None
     """
     LOG.debug(f'Setting {self.smog_desc} as {smog}')
     self.smog = Score(smog)
示例#3
0
 def setARI(self, ari: float) -> None:
     """
     Set the ARI Score
     :param ari: Set the ARI Score
     :return: None
     """
     LOG.debug(f'Setting {self.ari_desc} as {ari}')
     self.ari = Score(ari)
示例#4
0
 def setGFI(self, gfi: float) -> None:
     """
     Set the GFI Score
     :param gfi: Set the GFI Score
     :return: None
     """
     LOG.debug(f'Setting {self.gfi_desc} as {gfi}')
     self.gfi = Score(gfi)
示例#5
0
 def setFKGL(self, fkgl: float) -> None:
     """
     Set the FKGL Score
     :param fkgl: The FKGL score value
     :return: None
     """
     LOG.debug(f'Setting {self.fkgl_desc} as {fkgl}')
     self.fkgl = Score(fkgl)
示例#6
0
 def setFRES(self, fres: float) -> None:
     """
     Set the FRES Score
     :param fres: The FRES score value
     :return: None
     """
     LOG.debug(f'Setting {self.fres_desc} as {fres}')
     self.fres = Score(fres)
示例#7
0
 def setFRY(self, fry: float) -> None:
     """
     Set the FRY Score
     :param fry: Set the FRY Score
     :return: None
     """
     LOG.debug(f'Setting {self.fry_desc} as {fry}')
     self.fry = Score(fry)
示例#8
0
 def setLWS(self, lws: float) -> None:
     """
     Set the LWS Score
     :param lws: Set the LWS Score
     :return: None
     """
     LOG.debug(f'Setting {self.lws_desc} as {lws}')
     self.lws = Score(lws)
示例#9
0
 def setCLI(self, cli: float) -> None:
     """
     Set the CLI Score
     :param cli: Set the CLI Score
     :return: None
     """
     LOG.debug(f'Setting {self.cli_desc} as {cli}')
     self.cli = Score(cli)
示例#10
0
 def __init__(self):
     LOG.debug(f"{__name__} init")
     self.fres: Score = Score(0.0)  # Flesch Reading Ease Score
     self.fkgl: Score = Score(0.0)  # Flesch-Kincaid Grade Level
     self.gfi: Score = Score(0.0)  # Gunning Fog Index
     self.ari: Score = Score(0.0)  # Automated Readability Index
     self.smog: Score = Score(0.0)  # Simple Measure of Gobbledygook
     self.cli: Score = Score(0.0)  # Coleman-Liau Index
     self.lws: Score = Score(0.0)  # Linsear Write Score
     self.fry: Score = Score(0.0)  # Fry Readability Formula
     self.fres_desc = "Flesch Reading Ease Score"
     self.fkgl_desc = "Flesch-Kincaid Grade Level"
     self.gfi_desc = "Gunning Fog Index"
     self.ari_desc = "Automated Readability Index"
     self.smog_desc = "Simple Measure of Gobbledygook"
     self.cli_desc = "Coleman-Liau Index"
     self.lws_desc = "Linsear Write Score"
     self.fry_desc = "Fry Readability Formula"
示例#11
0
 def setUp(self) -> None:
     self.score = Score(1.18991)