# Path: schema_salad/exceptions.py
# class SchemaException(SchemaSaladException):
#     """Indicates error with the provided schema definition."""
# 
# Path: schema_salad/utils.py
# def add_dictlist(di, key, val):  # type: (Dict[Any, Any], Any, Any) -> None
# def aslist(thing):  # type: (Any) -> MutableSequence[Any]
# def flatten(thing, ltypes=(list, tuple)):
# def onWindows():
# def convert_to_dict(j4):  # type: (Any) -> Any
# def json_dump(
#     obj,  # type: Any
#     fp,  # type: IO[str]
#     **kwargs  # type: Any
# ):  # type: (...) -> None
# def json_dumps(
#     obj,  # type: Any
#     **kwargs  # type: Any
# ):  # type: (...) -> str
# def stdout() -> BufferedWriter:
#     def construct_yaml_timestamp(self: Any, node: Any, values: Any = None) -> Any:
# def yaml_no_ts() -> YAML:
# class _RoundTripNoTimeStampConstructor(RoundTripConstructor):


import logging
import unicodedata
import rdflib
import rdflib.namespace
from typing import (
    Any,
    Dict,
    Iterable,
    List,
    MutableMapping,
    MutableSequence,
    Optional,
    Tuple,
    Union,
    cast,
)
from urllib.parse import urldefrag, urlsplit
from rdflib import Graph, URIRef
from rdflib.namespace import RDF, RDFS
from ruamel.yaml.comments import CommentedMap, CommentedSeq
from .exceptions import SchemaException
from .utils import ContextType, aslist, json_dumps
) -> Graph:
    prefixes = {}
    idfields = []
    for k, v in ctx.items():
        if isinstance(v, MutableMapping):
            url = v["@id"]
        else:
            url = v
        if url == "@id":
            idfields.append(k)
        doc_url, frg = urldefrag(url)
        if "/" in frg:
            p = frg.split("/")[0]
            prefixes[p] = f"{doc_url}#{p}/"

    fix_jsonld_ids(wf, idfields)

    g = Graph() if graph is None else graph

    if isinstance(wf, MutableSequence):
        for w in wf:
            w["@context"] = ctx
            g.parse(
                data=json_dumps(w, default=str),
                format="json-ld",
                publicID=str(workflow),
            )
    elif isinstance(wf, MutableMapping):
        wf["@context"] = ctx
        g.parse(

# Path: schema_salad/exceptions.py
# class SchemaException(SchemaSaladException):
#     """Indicates error with the provided schema definition."""
# 
# Path: schema_salad/utils.py
# def add_dictlist(di, key, val):  # type: (Dict[Any, Any], Any, Any) -> None
# def aslist(thing):  # type: (Any) -> MutableSequence[Any]
# def flatten(thing, ltypes=(list, tuple)):
# def onWindows():
# def convert_to_dict(j4):  # type: (Any) -> Any
# def json_dump(
#     obj,  # type: Any
#     fp,  # type: IO[str]
#     **kwargs  # type: Any
# ):  # type: (...) -> None
# def json_dumps(
#     obj,  # type: Any
#     **kwargs  # type: Any
# ):  # type: (...) -> str
# def stdout() -> BufferedWriter:
#     def construct_yaml_timestamp(self: Any, node: Any, values: Any = None) -> Any:
# def yaml_no_ts() -> YAML:
# class _RoundTripNoTimeStampConstructor(RoundTripConstructor):


# Path: schema_salad/jsonld_context.py
import logging
import unicodedata
import rdflib
import rdflib.namespace
from typing import (
    Any,
    Dict,
    Iterable,
    List,
    MutableMapping,
    MutableSequence,
    Optional,
    Tuple,
    Union,
    cast,
)
from urllib.parse import urldefrag, urlsplit
from rdflib import Graph, URIRef
from rdflib.namespace import RDF, RDFS
from ruamel.yaml.comments import CommentedMap, CommentedSeq
from .exceptions import SchemaException
from .utils import ContextType, aslist, json_dumps

) -> Graph:
    prefixes = {}
    idfields = []
    for k, v in ctx.items():
        if isinstance(v, MutableMapping):
            url = v["@id"]
        else:
            url = v
        if url == "@id":
            idfields.append(k)
        doc_url, frg = urldefrag(url)
        if "/" in frg:
            p = frg.split("/")[0]
            prefixes[p] = f"{doc_url}#{p}/"

    fix_jsonld_ids(wf, idfields)

    g = Graph() if graph is None else graph

    if isinstance(wf, MutableSequence):
        for w in wf:
            w["@context"] = ctx
            g.parse(
                data=json_dumps(w, default=str),
                format="json-ld",
                publicID=str(workflow),
            )
    elif isinstance(wf, MutableMapping):
        wf["@context"] = ctx
        g.parse(

            data=json_dumps(wf, default=str), format="json-ld", publicID=str(workflow)