Skip to content
Snippets Groups Projects
Select Git revision
  • f23e1c77d734bce373adeda79a6d55b84b17c669
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

WindowTopMenu.test.js

Blame
  • unlizeXmlNbSample.ipynb 3.49 KiB
    In [1]:
    import tempfile
    import os
    import re
    from subprocess import Popen, PIPE, STDOUT
    from IPython.core.display import SVG
    def unl2dot(text, path):
        with tempfile.NamedTemporaryFile() as temp:
            out_name = os.path.basename(temp.name)
            out_dir = os.path.dirname(temp.name)
    
        with tempfile.NamedTemporaryFile(mode="w") as in_file:
            # Remove CRLF and flush output to avoid java errors
            in_file.write(text.replace("\r\n", "\n"))
            in_file.flush()
    
            # Run java parser
            cmd = ['java', '-jar', path,
                   '--input-file', in_file.name,
                   '--output-Dir', out_dir, '--output-file', out_name,
                   '--output-type', 'dot']
    
            with Popen(cmd, stdout=PIPE, stderr=STDOUT) as p:
                p.wait()
                p.stdout.flush()
                if p.returncode != 0:
                    print("Error in unl2rdf: \n\n"+p.stdout.read().decode())
                    print('UNL;')
                    print(text)
    
        # generate dot output
        fname = '{}/{}.dot'.format(out_dir, out_name)
        cmd = ['dot', '-Tsvg', fname]
        with Popen(cmd, stdout=PIPE, stderr=PIPE) as p:
            p.wait()
            if p.returncode != 0:
                print("Error creating svg: \n\n"+p.stderr.read().decode())
                print('UNL:')
                print(text)
                try:
                    with open(fname) as f:
                        print('DOT:')
                        print(f.read())
                except FileNotFoundError:
                    pass
            else:
                svg = p.stdout.read().decode()
                os.remove(fname)
                return svg
        return ""
    
    
    def displayUnl(unldata) :
    # We generate protoSVG because whent there are several sentences, 
    # a string composed of several concatenated SVG is produced (not a valid SVG).
    # We must then split the string to obtain several valid SVG to display.
        protoSvg = unl2dot(unldata, "unl2rdf-app-1.0-SNAPSHOT-jar-with-dependencies.jar")
        sep = "</svg>\n"
        svgArray = [x+sep for x in protoSvg.split(sep)]
        svgArray.pop()
        for svg in svgArray :
            text = re.search('\{org.*\n(.*)\n.*org\}',unldata).group(1)
            print(text)
            display(SVG(svg))