Ejemplo n.º 1
0
class TestDedocManager(TestCase):
    path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), "..", "data"))
    config = get_config()
    manager_config = get_manager_config(config=config)
    dedoc_manager = DedocManager.from_config(version="test",
                                             manager_config=manager_config,
                                             config=config)

    def test_parse_file(self):
        filename = "csv_tab.tsv"
        result = self.dedoc_manager.parse_file(
            os.path.join(self.path, "csv_tab.tsv"), {})
        self.assertEqual(filename, result.metadata.file_name)
        self.assertEqual(filename, result.metadata.file_name)
        self.assertLessEqual(["1", "2", "3"],
                             result.content.tables[0].cells[0])
        self.assertLessEqual(["2", "1", "5"],
                             result.content.tables[0].cells[1])
        self.assertLessEqual(["5", "3", "1"],
                             result.content.tables[0].cells[2])

    def test_version(self):
        self.assertEqual("test", self.dedoc_manager.version)

    def test_file_not_exists(self):
        with self.assertRaises(FileNotFoundError):
            self.dedoc_manager.parse_file("afagahcr", {})
Ejemplo n.º 2
0
 def get_api_dict(api: Api,
                  depth: int = 0,
                  name: str = 'TreeNode') -> Model:
     return api.model(
         name, {
             'node_id':
             fields.String(
                 description=
                 "Document element identifier. It is unique within one tree (i.e. "
                 "there will be no other such node_id in this tree, but in attachment "
                 "it may occur) The identifier has the form 0.2.1 where each number "
                 "means a serial number at the corresponding level of the hierarchy.",
                 required=True,
                 example="0.2.1"),
             'text':
             fields.String(description="text of node",
                           required=True,
                           example="Закон"),
             'annotations':
             fields.List(
                 fields.Nested(Annotation.get_api_dict(api),
                               description="Text annotations "
                               "(font, size, bold, italic and etc)")),
             'metadata':
             fields.Nested(ParagraphMetadata.get_api_dict(api),
                           skip_none=True,
                           allow_null=False,
                           description="Paragraph meta information"),
             'subparagraphs':
             fields.List(
                 fields.Nested(api.model('others_TreeNode', {})),
                 description=
                 "Node childes (with type 'TreeNode') of structure tree")
             if depth == get_config()['recursion_deep_subparagraphs'] else
             fields.List(
                 fields.Nested(
                     TreeNode.get_api_dict(
                         api,
                         depth=depth +
                         1,
                         name='refTreeNode' + str(depth))),
                 description=
                 "Node childes (with type 'TreeNode') of structure tree")
         })
Ejemplo n.º 3
0
 def get_api_dict(api: Api,
                  depth: int = 0,
                  name: str = 'ParsedDocument') -> Model:
     return api.model(
         name, {
             'content':
             fields.Nested(DocumentContent.get_api_dict(api),
                           description='Document content structure'),
             'metadata':
             fields.Nested(DocumentMetadata.get_api_dict(api),
                           allow_null=False,
                           skip_none=True,
                           description='Document meta information'),
             'version':
             fields.String(
                 description=
                 'the version of the program that parsed this document',
                 example="2020.07.11"),
             'warnings':
             fields.List(
                 fields.String(
                     description='list of warnings and possible errors',
                     example="DOCX: seems that document corrupted")),
             'attachments':
             fields.List(fields.Nested(
                 api.model('others_ParsedDocument', {})),
                         description='structure of attachments',
                         required=False) if depth
             == get_config()['recursion_deep_attachments'] else fields.List(
                 fields.Nested(ParsedDocument.get_api_dict(
                     api,
                     depth=depth + 1,
                     name='refParsedDocument' + str(depth)),
                               description='Attachment structure',
                               required=False))
         })
Ejemplo n.º 4
0
from dedoc.config import get_config

config = get_config()


def get_command_keep_models():
    """
    Ignore some private models in swagger api documentations
    """
    none_display = "{display: none !important}"
    discription = "API <style> " + ' '.join(["div#model-refTreeNode{depth} {none_display}"
                                            .format(depth=i, none_display=none_display)
                                             for i in range(config['recursion_deep_subparagraphs'])]) \
                  + ' '.join(["div#model-refParsedDocument{depth} {none_display}"
                             .format(depth=i, none_display=none_display)
                              for i in range(config['recursion_deep_attachments'])]) \
                  + " div#model-others_ParsedDocument {none_display} ".format(none_display=none_display) \
                  + " div#model-others_TreeNode {none_display}".format(none_display=none_display)\
                  + " div#model-Predicts {none_display}".format(none_display=none_display)\
                  + " </style>"

    return discription