Ejemplo n.º 1
0
def _infer_single_relation_stances(relation):
    """A helper method for extract_relations_stances(). It queries the database
    for an individual group a member has relations with and extracts stances
    from it.
    
    Arguments:
        relation: the relationship to examine (identifies a group)
    
    Returns:
        A list of all stances extracted from the relation
    """
    results = []
    # Check if the relation group is identified by name or id or synonym.
    query = queries.group_query(relation.group)
    group = PymongoDB.get_db().find_one(db_constants.GROUPS, query)

    if group is None:
        logger.LOGGER.error("Group not found: %s" % relation.group)
        return results

    logger.LOGGER.info("Inferring stances from group: %s" % group.name)
    for stance in group.stances:
        stance.relation = relation
        results.append(stance)

    return results
    def _run(self):
        """Implements the logic of Best for the Country."""
        result = self._consensus()

        country = PymongoDB.get_db().find_one(db_constants.GROUPS,
            queries.group_query(self._COUNTRY))

        if not country:
            logger.LOGGER.warning("Country group not found in DB.")
            return

        filter_fun = lambda stance: queries.is_group_identified(stance.source, country)

        country_for = filter(filter_fun, self._decision.groups_for)
        country_agn = filter(filter_fun, self._decision.groups_agn)

        if result == outcomes.FOR and country_for and not country_agn:
            self._country_stances = country_for
            self._set_decision(result)
        elif result == outcomes.AGN and country_agn and not country_for:
            self._country_stances = country_agn
            self._set_decision(result)