Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
dep2pict
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
dep2pict
dep2pict
Commits
3d4411bd
Commit
3d4411bd
authored
Feb 24, 2018
by
Bruno Guillaume
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add json mode for annot_tool
parent
a128b3d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
src/global.ml
src/global.ml
+3
-2
src/main.ml
src/main.ml
+32
-0
No files found.
src/global.ml
View file @
3d4411bd
...
...
@@ -50,13 +50,13 @@ let critical msg = ksprintf
|
Found
i
->
Some
(
String
.
sub
file_name
i
(
len
-
i
))
module
Format
=
struct
type
format
=
Dep
|
Conll
|
Png
|
Svg
|
Pdf
|
No_suff
|
Unk
of
string
type
format
=
Dep
|
Conll
|
Png
|
Svg
|
Pdf
|
Json
|
No_suff
|
Unk
of
string
let
get
file
=
match
get_suffix
file
with
|
None
->
Log
.
fwarning
"Cannot guess format (no suffix) for file
\"
%s
\"
"
file
;
No_suff
|
Some
suff
->
try
List
.
assoc
suff
[
(
".dep"
,
Dep
);
(
".conll"
,
Conll
);
(
".conllu"
,
Conll
);
(
".png"
,
Png
);
(
".svg"
,
Svg
);
(
".pdf"
,
Pdf
)]
try
List
.
assoc
suff
[
(
".dep"
,
Dep
);
(
".conll"
,
Conll
);
(
".conllu"
,
Conll
);
(
".png"
,
Png
);
(
".svg"
,
Svg
);
(
".pdf"
,
Pdf
)
;
(
".json"
,
Json
)
]
with
Not_found
->
Log
.
fwarning
"Unkwnow file extension
\"
%s
\"
for file
\"
%s
\"
"
suff
file
;
Unk
suff
let
to_string
=
function
...
...
@@ -65,6 +65,7 @@ module Format = struct
|
Png
->
"png"
|
Svg
->
"svg"
|
Pdf
->
"pdf"
|
Json
->
"json"
|
No_suff
->
"no_suff"
|
Unk
suff
->
sprintf
"unknown suffix '%s'"
suff
end
...
...
src/main.ml
View file @
3d4411bd
...
...
@@ -77,6 +77,35 @@ let rec parse_arg = function
end
;
parse_arg
tail
let
json_apply
json_in
json_out
=
match
json_in
with
|
`List
l
->
let
(
new_json
:
Yojson
.
Basic
.
json
)
=
`List
(
List
.
map
(
function
|
`Assoc
item
->
begin
match
List
.
assoc_opt
"dep_file"
item
with
|
Some
(
`String
dep_file
)
->
let
out_file
=
(
Filename
.
chop_extension
dep_file
)
^
".svg"
in
let
dep
=
Dep2pict
.
from_dep
(
File
.
read
dep_file
)
in
Dep2pict
.
save_svg
~
filename
:
out_file
dep
;
let
new_fields
=
match
Dep2pict
.
highlight_shift
()
with
|
Some
f
->
[(
"svg_file"
,
`String
out_file
);
(
"shift"
,
`Float
f
)]
|
None
->
[(
"svg_file"
,
`String
out_file
)]
in
`Assoc
(
item
@
new_fields
)
|
_
->
Log
.
warning
"Json items should contain a
\"
del_file
\"
field"
;
exit
0
end
|
_
->
Log
.
warning
"Json input file should be a list of Assoc list"
;
exit
0
)
l
)
in
let
out_ch
=
open_out
json_out
in
Printf
.
fprintf
out_ch
"%s
\n
"
(
Yojson
.
Basic
.
pretty_to_string
(
new_json
));
close_out
out_ch
|
_
->
Log
.
warning
"Json input file should be a list"
;
exit
0
(* (Yojson.Basic.pretty_to_string json) *)
(* -------------------------------------------------------------------------------- *)
let
_
=
let
()
=
parse_arg
(
List
.
tl
(
Array
.
to_list
Sys
.
argv
))
in
...
...
@@ -98,6 +127,9 @@ let _ =
Log
.
warning
"Dep2pict was compiled without lablwebkit, the GUI in not available"
;
exit
0
#
endif
|
Some
out_file
->
if
(
Format
.
get
!
input_file
)
=
Format
.
Json
then
json_apply
(
Yojson
.
Basic
.
from_file
!
input_file
)
out_file
else
try
load
!
input_file
;
set_position
()
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment