예제 #1
0
class LoadBox(W.HBox):
    formats = ",".join(["." + ext for ext in SUFFIX_FORMAT_MAP.keys()])
    graph = T.Instance(Graph)
    graph_id = T.Instance(BNode)
    label = T.Instance(W.Label)
    file_upload = T.Instance(W.FileUpload)
    file_upload_value = T.Dict()
    log = W.Output()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.children = tuple([self.label, self.file_upload])
        T.dlink((self.file_upload, "value"), (self, "file_upload_value"))

    @T.default("graph")
    def make_default_graph(self):
        return Graph()

    @T.default("graph_id")
    def make_default_graph_id(self):
        return self.graph.identifier

    @T.default("label")
    def make_default_label(self):
        label = W.Label(value="Click to load file:")
        return label

    @T.default("file_upload")
    def make_default_file_upload(self):
        # TODO support multiple files
        file_upload = W.FileUpload(accept=self.formats, multiple=False)
        return file_upload

    @T.observe("file_upload_value")
    def process_files(self, change):
        # TODO loader for files (not needed until support for >1 file)
        # size is in bytes
        file_graphs = {}
        for file_name, data in change.new.items():
            assert "metadata" and "content" in data
            assert file_name not in file_graphs
            file_graphs[file_name] = {}
            file_graphs[file_name]["metadata"] = data["metadata"]
            file_format = guess_format(file_name)
            if file_format is None:
                raise ValueError("Unknown file format.")
            g = Graph().parse(data=data["content"], format=file_format)
            file_graphs[file_name]["graph"] = g
            file_graphs[file_name]["metadata"]["length"] = len(g)

            # TODO combine graphs when multiple=True
            self.graph = g
            self.graph_id = g.identifier
예제 #2
0
파일: rdf.py 프로젝트: rfResearch/udata
namespace_manager = NamespaceManager(Graph())
namespace_manager.bind('dcat', DCAT)
namespace_manager.bind('dct', DCT)
namespace_manager.bind('foaf', FOAF)
namespace_manager.bind('foaf', FOAF)
namespace_manager.bind('hydra', HYDRA)
namespace_manager.bind('rdfs', RDFS)
namespace_manager.bind('scv', SCV)
namespace_manager.bind('skos', SKOS)
namespace_manager.bind('vcard', VCARD)
namespace_manager.bind('xsd', XSD)
namespace_manager.bind('freq', FREQ)

# Support JSON-LD in format detection
FORMAT_MAP = SUFFIX_FORMAT_MAP.copy()
FORMAT_MAP['json'] = 'json-ld'
FORMAT_MAP['jsonld'] = 'json-ld'
FORMAT_MAP['xml'] = 'xml'

# Map serialization formats to MIME types
RDF_MIME_TYPES = {
    'xml': 'application/rdf+xml',
    'n3': 'text/n3',
    'turtle': 'application/x-turtle',
    'nt': 'application/n-triples',
    'json-ld': 'application/ld+json',
    'trig': 'application/trig',
    # Available but not activated
    # 'nquads': 'application/n-quads',
    # 'trix': 'text/xml',
예제 #3
0
def rdf_suffix(fmt: str) -> str:
    """ Map the RDF format to the approproate suffix """
    for k, v in SUFFIX_FORMAT_MAP.items():
        if fmt == v:
            return k
    return 'rdf'
예제 #4
0
def rdf_suffix(fmt: str) -> str:
    """ Map the RDF format to the approproate suffix """
    for k, v in SUFFIX_FORMAT_MAP.items():
        if fmt == v:
            return k
    return 'rdf'
예제 #5
0
파일: rdf.py 프로젝트: odtvince/udata
namespace_manager = NamespaceManager(Graph())
namespace_manager.bind('dcat', DCAT)
namespace_manager.bind('dct', DCT)
namespace_manager.bind('foaf', FOAF)
namespace_manager.bind('foaf', FOAF)
namespace_manager.bind('hydra', HYDRA)
namespace_manager.bind('rdfs', RDFS)
namespace_manager.bind('scv', SCV)
namespace_manager.bind('skos', SKOS)
namespace_manager.bind('vcard', VCARD)
namespace_manager.bind('xsd', XSD)
namespace_manager.bind('freq', FREQ)

# Support JSON-LD in format detection
FORMAT_MAP = SUFFIX_FORMAT_MAP.copy()
FORMAT_MAP['json'] = 'json-ld'
FORMAT_MAP['jsonld'] = 'json-ld'
FORMAT_MAP['xml'] = 'xml'

# Map serialization formats to MIME types
RDF_MIME_TYPES = {
    'xml': 'application/rdf+xml',
    'n3': 'text/n3',
    'turtle': 'application/x-turtle',
    'nt': 'application/n-triples',
    'json-ld': 'application/ld+json',
    'trig': 'application/trig',
    # Available but not activated
    # 'nquads': 'application/n-quads',
    # 'trix': 'text/xml',