package(default_visibility = ["//visibility:public"])

cc_binary(
    name = "dragnn_cc_impl.so",
    linkopts = select({
        "//conditions:default": ["-lm"],
        "@org_tensorflow//tensorflow:darwin": [],
    }),
    linkshared = 1,
    linkstatic = 1,
    deps = [
        "//dragnn/components/stateless:stateless_component",
        "//dragnn/components/syntaxnet:syntaxnet_component",
        "//dragnn/core:dragnn_bulk_ops_cc",
        "//dragnn/core:dragnn_ops_cc",
    ],
)

py_library(
    name = "load_dragnn_cc_impl_py",
    srcs = ["load_dragnn_cc_impl.py"],
    data = [":dragnn_cc_impl.so"],
)

py_library(
    name = "bulk_component",
    srcs = [
        "bulk_component.py",
    ],
    deps = [
        ":dragnn_ops",
        ":network_units",
        "//syntaxnet/util:check",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_library(
    name = "components",
    srcs = [
        "component.py",
    ],
    deps = [
        ":bulk_component",
        ":dragnn_ops",
        ":network_units",
        "//syntaxnet/util:check",
        "//syntaxnet/util:pyregistry",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_library(
    name = "composite_optimizer",
    srcs = ["composite_optimizer.py"],
    deps = [
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_library(
    name = "dragnn_ops",
    srcs = ["dragnn_ops.py"],
    deps = [],
)

py_library(
    name = "graph_builder",
    srcs = ["graph_builder.py"],
    deps = [
        ":biaffine_units",
        ":components",
        ":composite_optimizer",
        ":dragnn_ops",
        ":network_units",
        ":wrapped_units",
        "//dragnn/protos:spec_py_pb2",
        "//syntaxnet/util:check",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_library(
    name = "network_units",
    srcs = ["network_units.py"],
    deps = [
        ":dragnn_ops",
        "//syntaxnet/util:check",
        "//syntaxnet/util:pyregistry",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_library(
    name = "render_parse_tree_graphviz",
    srcs = ["render_parse_tree_graphviz.py"],
    deps = [
    ],
)

py_test(
    name = "render_parse_tree_graphviz_test",
    srcs = ["render_parse_tree_graphviz_test.py"],
    deps = [
        ":render_parse_tree_graphviz",
        "//syntaxnet:sentence_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_library(
    name = "render_spec_with_graphviz",
    srcs = ["render_spec_with_graphviz.py"],
    deps = [
        "//dragnn/protos:spec_py_pb2",
    ],
)

py_test(
    name = "render_spec_with_graphviz_test",
    srcs = ["render_spec_with_graphviz_test.py"],
    deps = [
        ":render_spec_with_graphviz",
        ":spec_builder",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_library(
    name = "sentence_io",
    srcs = ["sentence_io.py"],
    deps = [
        "//syntaxnet:parser_ops",
    ],
)

py_binary(
    name = "visualization",
    srcs = ["visualization.py"],
    data = [
        "//dragnn/viz:viz-min-js-gz",
    ],
    deps = [
        "//dragnn/protos:trace_py_pb2",
    ],
)

py_test(
    name = "visualization_test",
    srcs = ["visualization_test.py"],
    deps = [
        ":visualization",
        "//dragnn/protos:spec_py_pb2",
        "//dragnn/protos:trace_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_library(
    name = "wrapped_units",
    srcs = ["wrapped_units.py"],
    deps = [
        ":network_units",
        "//syntaxnet/util:check",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

# Tests

py_test(
    name = "bulk_component_test",
    srcs = [
        "bulk_component_test.py",
    ],
    deps = [
        ":bulk_component",
        ":components",
        ":dragnn_ops",
        ":load_dragnn_cc_impl_py",
        ":network_units",
        "//dragnn/core:dragnn_bulk_ops",
        "//dragnn/core:dragnn_ops",
        "//dragnn/protos:spec_py_pb2",
        "//syntaxnet:load_parser_ops_py",
        "//syntaxnet:sentence_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_test(
    name = "composite_optimizer_test",
    srcs = ["composite_optimizer_test.py"],
    deps = [
        ":composite_optimizer",
        ":load_dragnn_cc_impl_py",
        "//dragnn/core:dragnn_bulk_ops",
        "//dragnn/core:dragnn_ops",
        "//syntaxnet:load_parser_ops_py",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_test(
    name = "graph_builder_test",
    size = "large",
    srcs = ["graph_builder_test.py"],
    data = [
        "//dragnn/core:testdata",
    ],
    tags = [
        "notsan",
    ],
    deps = [
        ":dragnn_ops",
        ":graph_builder",
        ":load_dragnn_cc_impl_py",
        "//dragnn/core:dragnn_bulk_ops",
        "//dragnn/core:dragnn_ops",
        "//dragnn/protos:spec_py_pb2",
        "//dragnn/protos:trace_py_pb2",
        "//syntaxnet:load_parser_ops_py",
        "//syntaxnet:sentence_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_test(
    name = "network_units_test",
    size = "small",
    srcs = ["network_units_test.py"],
    deps = [
        ":load_dragnn_cc_impl_py",
        ":network_units",
        "//dragnn/core:dragnn_bulk_ops",
        "//dragnn/core:dragnn_ops",
        "//dragnn/protos:spec_py_pb2",
        "//syntaxnet:load_parser_ops_py",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_test(
    name = "sentence_io_test",
    srcs = ["sentence_io_test.py"],
    data = ["//syntaxnet:testdata"],
    deps = [
        ":sentence_io",
        "//syntaxnet:load_parser_ops_py",
        "//syntaxnet:parser_ops",
        "//syntaxnet:sentence_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_library(
    name = "trainer_lib",
    srcs = ["trainer_lib.py"],
    deps = [
        "//dragnn/protos:spec_py_pb2",
        "//syntaxnet:parser_ops",
        "//syntaxnet:sentence_py_pb2",
        "//syntaxnet:task_spec_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

py_library(
    name = "lexicon",
    srcs = ["lexicon.py"],
    deps = [
        "//syntaxnet:parser_ops",
        "//syntaxnet:task_spec_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_test(
    name = "lexicon_test",
    srcs = ["lexicon_test.py"],
    deps = [
        ":lexicon",
        "//syntaxnet:load_parser_ops_py",
        "//syntaxnet:parser_ops",
        "//syntaxnet:parser_trainer",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_library(
    name = "evaluation",
    srcs = ["evaluation.py"],
    deps = [
        "//syntaxnet:sentence_py_pb2",
        "//syntaxnet/util:check",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_test(
    name = "evaluation_test",
    srcs = ["evaluation_test.py"],
    deps = [
        ":evaluation",
        "//syntaxnet:sentence_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_library(
    name = "spec_builder",
    srcs = ["spec_builder.py"],
    deps = [
        ":lexicon",
        "//dragnn/protos:spec_py_pb2",
        "//syntaxnet:parser_ops",
        "//syntaxnet/util:check",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_test(
    name = "spec_builder_test",
    srcs = ["spec_builder_test.py"],
    deps = [
        ":spec_builder",
        "//dragnn/protos:spec_py_pb2",
        "//syntaxnet:load_parser_ops_py",
        "//syntaxnet:parser_ops",
        "//syntaxnet:parser_trainer",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_library(
    name = "digraph_ops",
    srcs = ["digraph_ops.py"],
    deps = [
        "//syntaxnet/util:check",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_test(
    name = "digraph_ops_test",
    srcs = ["digraph_ops_test.py"],
    deps = [
        ":digraph_ops",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)

py_library(
    name = "biaffine_units",
    srcs = ["biaffine_units.py"],
    deps = [
        ":digraph_ops",
        ":network_units",
        "//syntaxnet/util:check",
        "@org_tensorflow//tensorflow:tensorflow_py",
    ],
)
