// Path: core/src/main/java/com/github/jsonldjava/utils/Obj.java
// public static Map<String, Object> newMap() {
//     return new LinkedHashMap<String, Object>(4, 0.75f);
// }
// 
// Path: core/src/main/java/com/github/jsonldjava/core/JsonLdError.java
// public enum Error {
//     LOADING_DOCUMENT_FAILED("loading document failed"),
// 
//     LIST_OF_LISTS("list of lists"),
// 
//     INVALID_INDEX_VALUE("invalid @index value"),
// 
//     CONFLICTING_INDEXES("conflicting indexes"),
// 
//     INVALID_ID_VALUE("invalid @id value"),
// 
//     INVALID_LOCAL_CONTEXT("invalid local context"),
// 
//     MULTIPLE_CONTEXT_LINK_HEADERS("multiple context link headers"),
// 
//     LOADING_REMOTE_CONTEXT_FAILED("loading remote context failed"),
// 
//     LOADING_INJECTED_CONTEXT_FAILED("loading injected context failed"),
// 
//     INVALID_REMOTE_CONTEXT("invalid remote context"),
// 
//     RECURSIVE_CONTEXT_INCLUSION("recursive context inclusion"),
// 
//     INVALID_BASE_IRI("invalid base IRI"),
// 
//     INVALID_VOCAB_MAPPING("invalid vocab mapping"),
// 
//     INVALID_DEFAULT_LANGUAGE("invalid default language"),
// 
//     KEYWORD_REDEFINITION("keyword redefinition"),
// 
//     INVALID_TERM_DEFINITION("invalid term definition"),
// 
//     INVALID_REVERSE_PROPERTY("invalid reverse property"),
// 
//     INVALID_IRI_MAPPING("invalid IRI mapping"),
// 
//     CYCLIC_IRI_MAPPING("cyclic IRI mapping"),
// 
//     INVALID_KEYWORD_ALIAS("invalid keyword alias"),
// 
//     INVALID_TYPE_MAPPING("invalid type mapping"),
// 
//     INVALID_LANGUAGE_MAPPING("invalid language mapping"),
// 
//     COLLIDING_KEYWORDS("colliding keywords"),
// 
//     INVALID_CONTAINER_MAPPING("invalid container mapping"),
// 
//     INVALID_TYPE_VALUE("invalid type value"),
// 
//     INVALID_VALUE_OBJECT("invalid value object"),
// 
//     INVALID_VALUE_OBJECT_VALUE("invalid value object value"),
// 
//     INVALID_LANGUAGE_TAGGED_STRING("invalid language-tagged string"),
// 
//     INVALID_LANGUAGE_TAGGED_VALUE("invalid language-tagged value"),
// 
//     INVALID_TYPED_VALUE("invalid typed value"),
// 
//     INVALID_SET_OR_LIST_OBJECT("invalid set or list object"),
// 
//     INVALID_LANGUAGE_MAP_VALUE("invalid language map value"),
// 
//     COMPACTION_TO_LIST_OF_LISTS("compaction to list of lists"),
// 
//     INVALID_REVERSE_PROPERTY_MAP("invalid reverse property map"),
// 
//     INVALID_REVERSE_VALUE("invalid @reverse value"),
// 
//     INVALID_REVERSE_PROPERTY_VALUE("invalid reverse property value"),
// 
//     INVALID_EMBED_VALUE("invalid @embed value"),
// 
//     // non spec related errors
//     SYNTAX_ERROR("syntax error"),
// 
//     NOT_IMPLEMENTED("not implemnted"),
// 
//     UNKNOWN_FORMAT("unknown format"),
// 
//     INVALID_INPUT("invalid input"),
// 
//     PARSE_ERROR("parse error"),
// 
//     UNKNOWN_ERROR("unknown error");
// 
//     private final String error;
// 
//     private Error(String error) {
//         this.error = error;
//     }
// 
//     @Override
//     public String toString() {
//         return error;
//     }
// }
// 
// Path: core/src/main/java/com/github/jsonldjava/impl/NQuadRDFParser.java
// public class NQuadRDFParser implements RDFParser {
//     @Override
//     public RDFDataset parse(Object input) throws JsonLdError {
//         if (input instanceof String) {
//             return RDFDatasetUtils.parseNQuads((String) input);
//         } else {
//             throw new JsonLdError(JsonLdError.Error.INVALID_INPUT,
//                     "NQuad Parser expected string input.");
//         }
//     }
// 
// }


import static com.github.jsonldjava.utils.Obj.newMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.jsonldjava.core.JsonLdError.Error;
import com.github.jsonldjava.impl.NQuadRDFParser;
import com.github.jsonldjava.impl.NQuadTripleCallback;
     * Builds the context to be returned in framing, flattening and compaction algorithms.
     * In cases where the context is empty or from an unexpected type, it returns null.
     * When JsonLdOptions compactArrays is set to true and the context contains a List with a single element,
     * the element is returned instead of the list
     */
    private static Object returnedContext(Object context, JsonLdOptions opts) {
        if (context != null &&
                ((context instanceof Map && !((Map<String, Object>) context).isEmpty())
                        || (context instanceof List && !((List<Object>) context).isEmpty())
                        || (context instanceof String && !((String) context).isEmpty()))) {

            if (context instanceof List && ((List<Object>) context).size() == 1
                    && opts.getCompactArrays()) {
                return ((List<Object>) context).get(0);
            }
            return context;
        } else {
            return null;
        }
    }

    /**
     * A registry for RDF Parsers (in this case, JSONLDSerializers) used by
     * fromRDF if no specific serializer is specified and options.format is set.
     *
     * TODO: this would fit better in the document loader class
     */
    private static Map<String, RDFParser> rdfParsers = new LinkedHashMap<String, RDFParser>() {
        {
            // automatically register nquad serializer
// Path: core/src/main/java/com/github/jsonldjava/utils/Obj.java
// public static Map<String, Object> newMap() {
//     return new LinkedHashMap<String, Object>(4, 0.75f);
// }
// 
// Path: core/src/main/java/com/github/jsonldjava/core/JsonLdError.java
// public enum Error {
//     LOADING_DOCUMENT_FAILED("loading document failed"),
// 
//     LIST_OF_LISTS("list of lists"),
// 
//     INVALID_INDEX_VALUE("invalid @index value"),
// 
//     CONFLICTING_INDEXES("conflicting indexes"),
// 
//     INVALID_ID_VALUE("invalid @id value"),
// 
//     INVALID_LOCAL_CONTEXT("invalid local context"),
// 
//     MULTIPLE_CONTEXT_LINK_HEADERS("multiple context link headers"),
// 
//     LOADING_REMOTE_CONTEXT_FAILED("loading remote context failed"),
// 
//     LOADING_INJECTED_CONTEXT_FAILED("loading injected context failed"),
// 
//     INVALID_REMOTE_CONTEXT("invalid remote context"),
// 
//     RECURSIVE_CONTEXT_INCLUSION("recursive context inclusion"),
// 
//     INVALID_BASE_IRI("invalid base IRI"),
// 
//     INVALID_VOCAB_MAPPING("invalid vocab mapping"),
// 
//     INVALID_DEFAULT_LANGUAGE("invalid default language"),
// 
//     KEYWORD_REDEFINITION("keyword redefinition"),
// 
//     INVALID_TERM_DEFINITION("invalid term definition"),
// 
//     INVALID_REVERSE_PROPERTY("invalid reverse property"),
// 
//     INVALID_IRI_MAPPING("invalid IRI mapping"),
// 
//     CYCLIC_IRI_MAPPING("cyclic IRI mapping"),
// 
//     INVALID_KEYWORD_ALIAS("invalid keyword alias"),
// 
//     INVALID_TYPE_MAPPING("invalid type mapping"),
// 
//     INVALID_LANGUAGE_MAPPING("invalid language mapping"),
// 
//     COLLIDING_KEYWORDS("colliding keywords"),
// 
//     INVALID_CONTAINER_MAPPING("invalid container mapping"),
// 
//     INVALID_TYPE_VALUE("invalid type value"),
// 
//     INVALID_VALUE_OBJECT("invalid value object"),
// 
//     INVALID_VALUE_OBJECT_VALUE("invalid value object value"),
// 
//     INVALID_LANGUAGE_TAGGED_STRING("invalid language-tagged string"),
// 
//     INVALID_LANGUAGE_TAGGED_VALUE("invalid language-tagged value"),
// 
//     INVALID_TYPED_VALUE("invalid typed value"),
// 
//     INVALID_SET_OR_LIST_OBJECT("invalid set or list object"),
// 
//     INVALID_LANGUAGE_MAP_VALUE("invalid language map value"),
// 
//     COMPACTION_TO_LIST_OF_LISTS("compaction to list of lists"),
// 
//     INVALID_REVERSE_PROPERTY_MAP("invalid reverse property map"),
// 
//     INVALID_REVERSE_VALUE("invalid @reverse value"),
// 
//     INVALID_REVERSE_PROPERTY_VALUE("invalid reverse property value"),
// 
//     INVALID_EMBED_VALUE("invalid @embed value"),
// 
//     // non spec related errors
//     SYNTAX_ERROR("syntax error"),
// 
//     NOT_IMPLEMENTED("not implemnted"),
// 
//     UNKNOWN_FORMAT("unknown format"),
// 
//     INVALID_INPUT("invalid input"),
// 
//     PARSE_ERROR("parse error"),
// 
//     UNKNOWN_ERROR("unknown error");
// 
//     private final String error;
// 
//     private Error(String error) {
//         this.error = error;
//     }
// 
//     @Override
//     public String toString() {
//         return error;
//     }
// }
// 
// Path: core/src/main/java/com/github/jsonldjava/impl/NQuadRDFParser.java
// public class NQuadRDFParser implements RDFParser {
//     @Override
//     public RDFDataset parse(Object input) throws JsonLdError {
//         if (input instanceof String) {
//             return RDFDatasetUtils.parseNQuads((String) input);
//         } else {
//             throw new JsonLdError(JsonLdError.Error.INVALID_INPUT,
//                     "NQuad Parser expected string input.");
//         }
//     }
// 
// }


// Path: core/src/main/java/com/github/jsonldjava/core/JsonLdProcessor.java
import static com.github.jsonldjava.utils.Obj.newMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.jsonldjava.core.JsonLdError.Error;
import com.github.jsonldjava.impl.NQuadRDFParser;
import com.github.jsonldjava.impl.NQuadTripleCallback;

     * Builds the context to be returned in framing, flattening and compaction algorithms.
     * In cases where the context is empty or from an unexpected type, it returns null.
     * When JsonLdOptions compactArrays is set to true and the context contains a List with a single element,
     * the element is returned instead of the list
     */
    private static Object returnedContext(Object context, JsonLdOptions opts) {
        if (context != null &&
                ((context instanceof Map && !((Map<String, Object>) context).isEmpty())
                        || (context instanceof List && !((List<Object>) context).isEmpty())
                        || (context instanceof String && !((String) context).isEmpty()))) {

            if (context instanceof List && ((List<Object>) context).size() == 1
                    && opts.getCompactArrays()) {
                return ((List<Object>) context).get(0);
            }
            return context;
        } else {
            return null;
        }
    }

    /**
     * A registry for RDF Parsers (in this case, JSONLDSerializers) used by
     * fromRDF if no specific serializer is specified and options.format is set.
     *
     * TODO: this would fit better in the document loader class
     */
    private static Map<String, RDFParser> rdfParsers = new LinkedHashMap<String, RDFParser>() {
        {
            // automatically register nquad serializer
            put(JsonLdConsts.APPLICATION_NQUADS, new NQuadRDFParser());