Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--debug", action="store_true")
    parser.add_argument("in_graph_1")
    parser.add_argument("in_graph_2")
    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)

    g1 = rdflib.Graph()
    g2 = rdflib.Graph()

    g1.parse(args.in_graph_1, format=case_utils.guess_format(args.in_graph_1))
    g2.parse(args.in_graph_2, format=case_utils.guess_format(args.in_graph_2))

    #_logger.debug("type(g1) = %r.", type(g1))
    #_logger.debug("type(g2) = %r.", type(g2))

    #_logger.debug("len(g1) = %d.", len(g1))
    #_logger.debug("len(g2) = %d.", len(g2))

    i1 = rdflib.compare.to_isomorphic(g1)
    i2 = rdflib.compare.to_isomorphic(g2)

    #_logger.debug("type(i1) = %r.", type(i1))
    #_logger.debug("type(i2) = %r.", type(i2))

    if i1 == i2:
        sys.exit(0)

    def _report(diff_symbol, graph):
        """
        This function copied in spirit from:
        https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#module-rdflib.compare
        """
        for line in sorted(graph.serialize(format="nt").splitlines()):
            if line.strip() == b"":
                continue
            _logger.debug("%s %s", diff_symbol, line.decode("ascii"))

    #_report("1", g1)
    #_report("2", g2)

    if args.debug:
        (
          in_both, 
          in_first,
          in_second
        ) = rdflib.compare.graph_diff(i1, i2)
        _report("<", in_first)
        _report(">", in_second)

    sys.exit(1)
def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("--base-prefix", default=DEFAULT_PREFIX)
    parser.add_argument("--disable-hashes", action="store_true")
    parser.add_argument("--disable-mtime", action="store_true")
    parser.add_argument("--output-format", help="Override extension-based format guesser.")
    parser.add_argument("out_graph")
    parser.add_argument("in_file")
    args = parser.parse_args()

    case_utils.local_uuid.configure()

    NS_BASE = rdflib.Namespace(args.base_prefix)

    graph = rdflib.Graph()
    graph.namespace_manager.bind("kb", NS_BASE)
    graph.namespace_manager.bind("uco-core", NS_UCO_CORE)
    graph.namespace_manager.bind("uco-observable", NS_UCO_OBSERVABLE)
    graph.namespace_manager.bind("uco-types", NS_UCO_TYPES)
    graph.namespace_manager.bind("uco-vocabulary", NS_UCO_VOCABULARY)
    graph.namespace_manager.bind("xsd", NS_XSD)

    output_format = None
    if args.output_format is None:
        output_format = case_utils.guess_format(args.out_graph)
    else:
        output_format = args.output_format

    serialize_kwargs = {
      "format": output_format
    }
    if output_format == "json-ld":
        context_dictionary = {k:v for (k,v) in graph.namespace_manager.namespaces()}
        serialize_kwargs["context"] = context_dictionary

    node_iri = NS_BASE["file-" + case_utils.local_uuid.local_uuid()]
    n_file = create_file_node(
      graph,
      args.in_file,
      node_iri=node_iri,
      node_prefix=args.base_prefix,
      disable_hashes=args.disable_hashes,
      disable_mtime=args.disable_mtime
    )

    graph.serialize(args.out_graph, **serialize_kwargs)
Esempio n. 3
0
def main():
    case_utils.local_uuid.configure()

    args = argument_parser.parse_args()
    logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)

    NS_BASE = rdflib.Namespace(args.base_prefix)
    out_graph = rdflib.Graph()

    out_graph.namespace_manager.bind("exiftool-Composite",
                                     NS_EXIFTOOL_COMPOSITE)
    out_graph.namespace_manager.bind("exiftool-et", NS_EXIFTOOL_ET)
    out_graph.namespace_manager.bind("exiftool-ExifTool", NS_EXIFTOOL_EXIFTOOL)
    out_graph.namespace_manager.bind("exiftool-System", NS_EXIFTOOL_SYSTEM)
    out_graph.namespace_manager.bind("exiftool-File", NS_EXIFTOOL_FILE)
    out_graph.namespace_manager.bind("exiftool-GPS", NS_EXIFTOOL_GPS)
    out_graph.namespace_manager.bind("exiftool-IFD0", NS_EXIFTOOL_IFD0)
    out_graph.namespace_manager.bind("exiftool-ExifIFD", NS_EXIFTOOL_EXIFIFD)
    out_graph.namespace_manager.bind("exiftool-Nikon", NS_EXIFTOOL_NIKON)
    out_graph.namespace_manager.bind("exiftool-PreviewIFD",
                                     NS_EXIFTOOL_PREVIEWIFD)
    out_graph.namespace_manager.bind("exiftool-InteropIFD",
                                     NS_EXIFTOOL_INTEROPIFD)
    out_graph.namespace_manager.bind("exiftool-IFD1", NS_EXIFTOOL_IFD1)
    out_graph.namespace_manager.bind("kb", NS_BASE)
    out_graph.namespace_manager.bind("uco-core", NS_UCO_CORE)
    out_graph.namespace_manager.bind("uco-location", NS_UCO_LOCATION)
    out_graph.namespace_manager.bind("uco-observable", NS_UCO_OBSERVABLE)
    out_graph.namespace_manager.bind("uco-types", NS_UCO_TYPES)
    out_graph.namespace_manager.bind("uco-vocabulary", NS_UCO_VOCABULARY)

    exiftool_rdf_mapper = ExifToolRDFMapper(out_graph, NS_BASE)
    exiftool_rdf_mapper.map_raw_and_printconv_rdf(args.raw_xml,
                                                  args.print_conv_xml)

    #_logger.debug("args.output_format = %r." % args.output_format)
    output_format = args.output_format or case_utils.guess_format(
        args.out_graph)

    out_graph.serialize(destination=args.out_graph, format=output_format)
def test_case_utils_guess_format_json_fmap():
    assert case_utils.guess_format(PATH_TO_JSON, FMAP_XHTML_GRDDL) == "json-ld", "Failed to recognize .json RDF file extension when using fmap"
def test_case_utils_guess_format_json_default():
    assert case_utils.guess_format(PATH_TO_JSON) == "json-ld", "Failed to recognize .json RDF file extension"
def test_case_utils_guess_format_ttl_fmap():
    assert case_utils.guess_format(PATH_TO_TTL, FMAP_XHTML_GRDDL) == "turtle", "Failed to recognize .ttl RDF file extension when using fmap"
def test_case_utils_guess_format_ttl_default():
    assert case_utils.guess_format(PATH_TO_TTL) == "turtle", "Failed to recognize .ttl RDF file extension"
Esempio n. 8
0
def main():
    g = rdflib.Graph()
    for in_graph in args.in_graph:
        g.parse(in_graph, format=case_utils.guess_format(in_graph))
    g.serialize(args.out_graph, format=case_utils.guess_format(args.out_graph))