Ejemplo n.º 1
0
    def annotate_taxonomy(self,
                          username,
                          unseen_only=True,
                          repo=None,
                          save=False):
        """Annotate taxonomy, meaning we iterate over repos and criteria that 
           match the user request, namely to annotate unseen only, or just
           a particular repository. If the repository is specified, unseen_only
           is assumed False.
        """
        annotations = {}

        # Retrieve the full taxonomy
        items = self.list_taxonomy()
        choices = [str(i) for i, _ in enumerate(items)] + ["s", "S", "skip"]
        prefix = "0:%s or s to skip" % (len(items) - 1)

        for repo in self.yield_taxonomy_annotation_repos(
                username, unseen_only, repo):

            message.info(f"\n{repo.url} [{repo.description}]:")
            print(
                "How would you categorize this software? [enter one or more numbers]"
            )
            for i, t in enumerate(items):
                example = t.get("example", "")
                name = t.get("name", "")
                if name and example:
                    print(f"[{i}] {name} ({example})")
                elif name:
                    print(f"[{i}] {name}")

            response = choice_prompt(
                "Please enter one or more numbers, separated by spaces",
                choices=choices,
                choice_prefix=prefix,
                multiple=True,
            )

            if response in ["s", "S", "skip"]:
                continue

            # Get the unique ids
            uids = [
                items[int(x)]["uid"] for x in set(response.split(" "))
                if int(x) < len(items)
            ]

            # Filesystem database we write filename to repository folder
            self.save_taxonomy(repo, username, uids)
            annotations[repo.uid] = repo.taxonomy

        return annotations
Ejemplo n.º 2
0
    def annotate_criteria(self,
                          username,
                          unseen_only=True,
                          repo=None,
                          save=False):
        """Annotate criteria, meaning we iterate over repos and criteria that 
           match the user request, namely to annotate unseen only, or just
           a particular repository. If the repository is specified, unseen_only
           is assumed False.
        """
        annotations = {}
        last = None
        for repo, criteria in self.yield_criteria_annotation_repos(
                username, unseen_only, repo):

            # Only print repository if not seen yet
            if not last or repo.uid != last.uid:

                # If we have a last repo, we need to save progress
                if last is not None and save is True:
                    self.save_criteria(last)

                if last is not None:
                    annotations[last.uid] = last.criteria

                message.info(f"\n{repo.url} [{repo.description}]:")
                last = repo

            response = choice_prompt(
                criteria["name"],
                choices=["y", "Y", "n", "N", "s", "S", "skip"],
                choice_prefix="y/n or s to skip",
            )

            # The user can skip an answer if wanted
            if response in ["s", "S", "skip"]:
                continue

            repo.update_criteria(criteria["uid"], username, response)

        # Save the last repository
        if last is not None and save is True:
            self.save_criteria(last)

        if last is not None:
            annotations[last.uid] = last.criteria
        return annotations
Ejemplo n.º 3
0
def analyze(args, extra):
    """analyze is intended to provide calculations for repos, by default including
    all taxonomy categories and criteria. For a custom set, the user should
    interact with the client directly.
    """
    client = Encyclopedia(config_file=args.config_file, database=args.database)
    result = client.analyze(repo=args.repo,
                            cthresh=args.cthresh,
                            tthresh=args.tthresh)

    # Create rows for criteria and taxonomy
    clookup = {c["uid"]: c for c in client.list_criteria()}
    tlookup = {t["uid"]: t for t in client.list_taxonomy()}
    crows = [[response, clookup[uid]["name"]]
             for uid, response in result["criteria"].items()]
    trows = [[str(count), tlookup[uid]["name"]]
             for uid, count in result["taxonomy"].items()]

    bot.info(f"Summary for {result['repo']}")
    bot.info("\nCriteria")
    bot.table(crows)
    bot.info("\nTaxonomy")
    bot.table(trows)