Ejemplo n.º 1
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(parse_text(info["description"]))

        if info["namespace"]:
            section_obj.append(
                paragraph("**Namespace**: %s" % info["namespace"]))

        if info["parameters"]:
            if base_name:
                ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
            else:
                ref_prefix = "%s-" % plugin_cls.get_name()

            section_obj.extend(
                self._make_pretty_parameters(info["parameters"], ref_prefix))

            if info["returns"]:
                section_obj.extend(
                    parse_text("**Returns**:\n%s" % info["returns"]))

        filename = info["module"].replace(".", "/")
        ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
        section_obj.extend(
            parse_text("**Module**:\n`%s`__\n\n__ %s" % (info["module"], ref)))
        return section_obj
Ejemplo n.º 2
0
def make_arguments_section(category_name, cmd_name, arguments, defaults):
    elements = [utils.paragraph("**Command arguments**:")]
    for args, kwargs in arguments:
        # for future changes...
        # :param args: a single command argument which can represented by
        #       several names(for example, --uuid and --task-id) in cli.
        # :type args: tuple
        # :param kwargs: description of argument. Have next format:
        #       {"dest": "action_kwarg_<name of keyword argument in code>",
        #        "help": "just a description of argument"
        #        "metavar": "[optional] metavar of argument. Example:"
        #                      "Example: argument '--file'; metavar 'path' ",
        #        "type": "[optional] class object of argument's type",
        #        "required": "[optional] boolean value"}
        # :type kwargs: dict
        dest = kwargs.get("dest").replace("action_kwarg_", "")
        description = []
        if cmd_name != "use":
            # lets add notes about specific default values and hint about
            # "use" command with reference
            if dest in ("deployment", "task"):
                description.append(compose_note_about_default_uuids(
                    args[0], dest))
                description.append(
                    compose_use_cmd_hint_msg("rally %s use" % dest))
            elif dest == "verification":
                description.append(compose_note_about_default_uuids(
                    args[0], dest))
                description.append(
                    compose_use_cmd_hint_msg("rally verify use"))

        description.append(kwargs.get("help"))

        action = kwargs.get("action")
        if not action:
            arg_type = kwargs.get("type")
            if arg_type:
                description.append("**Type**: %s" % arg_type.__name__)

            skip_default = dest in ("deployment",
                                    "task_id",
                                    "verification")
            if not skip_default and dest in defaults:
                description.append("**Default**: %s" % defaults[dest])
        metavar = kwargs.get("metavar")

        ref = "%s_%s_%s" % (category_name, cmd_name, args[0].replace("-", ""))

        if metavar:
            args = ["%s %s" % (arg, metavar) for arg in args]

        elements.extend(utils.make_definition(", ".join(args),
                                              ref, description))
    return elements
Ejemplo n.º 3
0
def main():
    # path = "./asset/Donald-Trump-vs-Barack-Obama-on-Nuclear-Weapons-in-East-Asia.txt"
    path = "./asset/People-Arent-Upgrading-Smartphones-as-Quickly-and-That-Is-Bad-for-Apple.txt"
    # path = "./asset/The-Last-Man-on-the-Moon--Eugene-Cernan-gives-a-compelling-account.txt"
    path_synsets = "./asset/synsets.txt"
    path_nasari = "./asset/dd-nasari.txt"

    # Lettura del file Synset ottenuto con lo script titleSynset.py
    synsets = utils.read_file_synset(path_synsets)
    # Dizionario di synsets con parola come key e babel synset id come valore
    word_to_synset = utils.word_to_synset_dict(synsets)

    # Lettura del file nasari
    nasari = utils.read_file_nasari(path_nasari)

    # Lettura file da testare
    text = utils.read_file(path)

    # Individuazione di 10 keyword nel file
    keywords = utils.get_key_words(text)
    # print(keywords)

    # Divisione del testo in titolo e paragrafi
    dictionary = utils.paragraph(text)
    # Pulizia del titolo con unione dei nomi propri in unico token ed eliminazione delle stop words
    dictionary = utils.clean_title(dictionary)
    # print(dictionary)

    # Determinazione del contesto
    context = get_context(dictionary["Titolo"], word_to_synset, nasari)
    # print(context)
    # context = []

    # Determinazione dell'importanza/rank dei paragrafi
    rank_p = rank_paragraphs(dictionary, context, keywords)
    rank_p2 = copy.deepcopy(rank_p)

    print("\n\n\nORIGINAL\n\n\n" + utils.generate_summary(rank_p))

    # Creazione riassunti con metodo trivial
    summary = summarize_trivial(
        rank_p2, ratio=0.3
    )  # Il ratio si può cambiare in base alla percentuale di riassunto
    print("\n\n\nSUMMARY TRIVIAL\n\n\n" + utils.generate_summary(summary))

    # Creazione riassunti con metodo efficiente
    summary = summarize(
        rank_p, ratio=0.3
    )  # Il ratio si può cambiare in base alla percentuale di riassunto
    print("\n\n\nSUMMARY\n\n\n" + utils.generate_summary(summary))

    # Salvataggio riassunti
    utils.save_summary(summary)
Ejemplo n.º 4
0
def make_arguments_section(category_name, cmd_name, arguments, defaults):
    elements = [utils.paragraph("**Command arguments**:")]
    for args, kwargs in arguments:
        # for future changes...
        # :param args: a single command argument which can represented by
        #       several names(for example, --uuid and --task-id) in cli.
        # :type args: tuple
        # :param kwargs: description of argument. Have next format:
        #       {"dest": "action_kwarg_<name of keyword argument in code>",
        #        "help": "just a description of argument"
        #        "metavar": "[optional] metavar of argument. Example:"
        #                      "Example: argument '--file'; metavar 'path' ",
        #        "type": "[optional] class object of argument's type",
        #        "required": "[optional] boolean value"}
        # :type kwargs: dict
        dest = kwargs.get("dest").replace("action_kwarg_", "")
        description = []
        if cmd_name != "use":
            # lets add notes about specific default values and hint about
            # "use" command with reference
            if dest in ("deployment", "task"):
                description.append(
                    compose_note_about_default_uuids(args[0], dest))
                description.append(
                    compose_use_cmd_hint_msg("rally %s use" % dest))
            elif dest == "verification":
                description.append(
                    compose_note_about_default_uuids(args[0], dest))
                description.append(
                    compose_use_cmd_hint_msg("rally verify use"))

        description.append(kwargs.get("help"))

        action = kwargs.get("action")
        if not action:
            arg_type = kwargs.get("type")
            if arg_type:
                description.append("**Type**: %s" % arg_type.__name__)

            skip_default = dest in ("deployment", "task_id", "verification")
            if not skip_default and dest in defaults:
                description.append("**Default**: %s" % defaults[dest])
        metavar = kwargs.get("metavar")

        ref = "%s_%s_%s" % (category_name, cmd_name, args[0].replace("-", ""))

        if metavar:
            args = ["%s %s" % (arg, metavar) for arg in args]

        elements.extend(
            utils.make_definition(", ".join(args), ref, description))
    return elements
Ejemplo n.º 5
0
    def _make_pretty_parameters(parameters, ref_prefix):
        if not parameters:
            return []

        results = [paragraph("**Parameters**:")]
        for p in parameters:
            pname = p["name"]
            ref = ("%s%s" % (ref_prefix, pname)).lower().replace(".", "-")
            if "type" in p:
                pname += " (%s)" % p["type"]
            pdoc = "\n  ".join(p["doc"].split("\n"))
            results.extend(make_definition(pname, ref, [pdoc]))
        return results
Ejemplo n.º 6
0
def make_plugin_section(plugin, base_name):
    subcategory_obj = subcategory("%s [%s]" % (plugin.get_name(), base_name))
    info = plugin.get_info()
    if info["title"]:
        subcategory_obj.append(paragraph(info["title"]))

    if info["description"]:
        subcategory_obj.extend(parse_text(info["description"]))

    if info["namespace"]:
        subcategory_obj.append(
            paragraph("**Namespace**: %s" % info["namespace"]))

    if info["parameters"]:
        subcategory_obj.extend(
            parse_text(_make_pretty_parameters(info["parameters"])))
        if info["returns"]:
            subcategory_obj.extend(
                parse_text("**Returns**:\n%s" % info["returns"]))
    filename = info["module"].replace(".", "/")
    ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
    subcategory_obj.extend(
        parse_text("**Module**:\n`%s`__\n\n__ %s" % (info["module"], ref)))
    return subcategory_obj
Ejemplo n.º 7
0
def make_plugin_section(plugin, base_name):
    subcategory_obj = subcategory("%s [%s]" % (plugin.get_name(), base_name))
    info = plugin.get_info()
    if info["title"]:
        subcategory_obj.append(paragraph(info["title"]))

    if info["description"]:
        subcategory_obj.extend(parse_text(info["description"]))

    if info["namespace"]:
        subcategory_obj.append(paragraph(
                "**Namespace**: %s" % info["namespace"]))

    if info["parameters"]:
        subcategory_obj.extend(parse_text(
                _make_pretty_parameters(info["parameters"])))
        if info["returns"]:
            subcategory_obj.extend(parse_text(
                    "**Returns**:\n%s" % info["returns"]))
    filename = info["module"].replace(".", "/")
    ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
    subcategory_obj.extend(parse_text("**Module**:\n`%s`__\n\n__ %s"
                                      % (info["module"], ref)))
    return subcategory_obj
Ejemplo n.º 8
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = utils.section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(utils.paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(utils.parse_text(info["description"]))

        if info["namespace"]:
            section_obj.append(
                utils.paragraph("**Namespace**: %s" % info["namespace"]))

        if base_name:
            ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
        else:
            ref_prefix = "%s-" % plugin_cls.get_name()

        if info["parameters"]:
            section_obj.extend(
                self._make_arg_items(info["parameters"], ref_prefix))

        if info["returns"]:
            section_obj.extend(
                utils.parse_text("**Returns**:\n%s" % info["returns"]))

        if info["schema"]:
            schema = process_jsonschema(info["schema"])
            if "type" in schema:
                if "parameters" in schema:
                    section_obj.extend(
                        self._make_arg_items(items=schema["parameters"],
                                             ref_prefix=ref_prefix))
                elif "patternProperties" in schema:
                    section_obj.extend(
                        self._make_arg_items(
                            items=schema["patternProperties"],
                            ref_prefix=ref_prefix,
                            description=[
                                "*Dictionary is expected. Keys should "
                                "follow pattern(s) described bellow.*"
                            ]))
                elif "oneOf" in schema:
                    section_obj.append(
                        utils.note("One of the following groups of "
                                   "parameters should be provided."))
                    for i, oneOf in enumerate(schema["oneOf"], 1):
                        description = None
                        if oneOf.get("doc", None):
                            description = [oneOf["doc"]]
                        section_obj.extend(
                            self._make_arg_items(
                                items=oneOf["parameters"],
                                ref_prefix=ref_prefix,
                                title="Option %s of parameters" % i,
                                description=description))
                else:
                    section_obj.extend(
                        self._make_arg_items(items=[schema],
                                             ref_prefix=ref_prefix))
            else:
                raise Exception("Failed to display provided schema: %s" %
                                info["schema"])

        if issubclass(plugin_cls, validation.ValidatablePluginMixin):
            validators = plugin_cls._meta_get("validators", default=[])
            platforms = [
                kwargs for name, args, kwargs in validators
                if name == "required_platform"
            ]
            if platforms:
                section_obj.append(
                    utils.paragraph("**Requires platform(s)**:"))
                section = ""
                for p in platforms:
                    section += "* %s" % p["platform"]
                    admin_msg = "credentials for admin user"
                    user_msg = ("regular users (temporary users can be created"
                                " via the 'users' context if admin user is "
                                "specified for the platform)")
                    if p.get("admin", False) and p.get("users", False):
                        section += " with %s and %s." % (admin_msg, user_msg)
                    elif p.get("admin", False):
                        section += " with %s." % admin_msg
                    elif p.get("users", False):
                        section += " with %s." % user_msg
                    section += "\n"

                section_obj.extend(utils.parse_text(section))

        filename = info["module"].replace(".", "/")
        ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
        section_obj.extend(
            utils.parse_text("**Module**:\n`%s`__\n\n__ %s" %
                             (info["module"], ref)))
        return section_obj
Ejemplo n.º 9
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(parse_text(info["description"]))

        if info["namespace"]:
            section_obj.append(
                paragraph("**Namespace**: %s" % info["namespace"]))

        if base_name:
            ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
        else:
            ref_prefix = "%s-" % plugin_cls.get_name()

        if info["parameters"]:
            section_obj.extend(
                self._make_arg_items(info["parameters"], ref_prefix))

        if info["returns"]:
            section_obj.extend(parse_text("**Returns**:\n%s" %
                                          info["returns"]))

        if info["schema"]:
            schema = process_jsonschema(info["schema"])
            if "type" in schema:
                if "parameters" in schema:
                    section_obj.extend(
                        self._make_arg_items(items=schema["parameters"],
                                             ref_prefix=ref_prefix))
                elif "patternProperties" in schema:
                    section_obj.extend(
                        self._make_arg_items(
                            items=schema["patternProperties"],
                            ref_prefix=ref_prefix,
                            description=[
                                "*Dictionary is expected. Keys should "
                                "follow pattern(s) described bellow.*"
                            ]))
                elif "oneOf" in schema:
                    section_obj.append(
                        note("One of the following groups of "
                             "parameters should be provided."))
                    for i, oneOf in enumerate(schema["oneOf"], 1):
                        description = None
                        if oneOf.get("doc", None):
                            description = [oneOf["doc"]]
                        section_obj.extend(
                            self._make_arg_items(
                                items=oneOf["parameters"],
                                ref_prefix=ref_prefix,
                                title="Option %s of parameters" % i,
                                description=description))
                else:
                    section_obj.extend(
                        self._make_arg_items(items=[schema],
                                             ref_prefix=ref_prefix))
            else:
                raise Exception("Failed to display provided schema: %s" %
                                info["schema"])

        filename = info["module"].replace(".", "/")
        ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
        section_obj.extend(
            parse_text("**Module**:\n`%s`__\n\n__ %s" % (info["module"], ref)))
        return section_obj
Ejemplo n.º 10
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = utils.section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(utils.paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(utils.parse_text(info["description"]))

        if info["platform"]:
            section_obj.append(utils.paragraph(
                "**Platform**: %s" % info["platform"]))

        if base_name:
            ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
        else:
            ref_prefix = "%s-" % plugin_cls.get_name()

        if info["parameters"]:
            section_obj.extend(self._make_arg_items(info["parameters"],
                                                    ref_prefix))

        if info["returns"]:
            section_obj.extend(utils.parse_text(
                "**Returns**:\n%s" % info["returns"]))

        if info["schema"]:
            schema = process_jsonschema(info["schema"])
            if "type" in schema:
                if "parameters" in schema:
                    section_obj.extend(self._make_arg_items(
                        items=schema["parameters"],
                        ref_prefix=ref_prefix))
                elif "patternProperties" in schema:
                    section_obj.extend(self._make_arg_items(
                        items=schema["patternProperties"],
                        ref_prefix=ref_prefix,
                        description=["*Dictionary is expected. Keys should "
                                     "follow pattern(s) described bellow.*"]))
                elif "oneOf" in schema:
                    section_obj.append(utils.note(
                        "One of the following groups of "
                        "parameters should be provided."))
                    for i, oneOf in enumerate(schema["oneOf"], 1):
                        description = None
                        if oneOf.get("doc", None):
                            description = [oneOf["doc"]]
                        section_obj.extend(self._make_arg_items(
                            items=oneOf["parameters"],
                            ref_prefix=ref_prefix,
                            title="Option %s of parameters" % i,
                            description=description))
                else:
                    section_obj.extend(self._make_arg_items(
                        items=[schema], ref_prefix=ref_prefix))
            else:
                raise Exception("Failed to display provided schema: %s" %
                                info["schema"])

        if issubclass(plugin_cls, validation.ValidatablePluginMixin):
            validators = plugin_cls._meta_get("validators", default=[])
            platforms = [kwargs for name, args, kwargs in validators
                         if name == "required_platform"]
            if platforms:
                section_obj.append(
                    utils.paragraph("**Requires platform(s)**:"))
                section = ""
                for p in platforms:
                    section += "* %s" % p["platform"]
                    admin_msg = "credentials for admin user"
                    user_msg = ("regular users (temporary users can be created"
                                " via the 'users' context if admin user is "
                                "specified for the platform)")
                    if p.get("admin", False) and p.get("users", False):
                        section += " with %s and %s." % (admin_msg, user_msg)
                    elif p.get("admin", False):
                        section += " with %s." % admin_msg
                    elif p.get("users", False):
                        section += " with %s." % user_msg
                    section += "\n"

                section_obj.extend(utils.parse_text(section))

        filename = info["module"].replace(".", "/")
        if filename.startswith("rally/"):
            project = "rally"
        elif filename.startswith("rally_openstack/"):
            project = "rally-openstack"
        else:
            # WTF is it?!
            return None
        ref = ("https://github.com/openstack/%s/blob/master/%s.py"
               % (project, filename))
        section_obj.extend(utils.parse_text("**Module**:\n`%s`__\n\n__ %s"
                           % (info["module"], ref)))
        return section_obj