// 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;

        // 9)
        return (Map<String, Object>) compacted;
    }

    /**
     * Expands the given input according to the steps in the
     * <a href="http://www.w3.org/TR/json-ld-api/#expansion-algorithm">Expansion
     * algorithm</a>.
     *
     * @param input
     *            The input JSON-LD object.
     * @param opts
     *            The {@link JsonLdOptions} that are to be sent to the expansion
     *            algorithm.
     * @return The expanded JSON-LD document
     * @throws JsonLdError
     *             If there is an error while expanding.
     */
    public static List<Object> expand(Object input, JsonLdOptions opts) throws JsonLdError {
        // 1)
        // TODO: look into java futures/promises

        // 2) TODO: better verification of DOMString IRI
        if (input instanceof String && ((String) input).contains(":")) {
            try {
                final RemoteDocument tmp = opts.getDocumentLoader().loadDocument((String) input);
                input = tmp.getDocument();
                // TODO: figure out how to deal with remote context
            } catch (final Exception e) {
// 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;


        // 9)
        return (Map<String, Object>) compacted;
    }

    /**
     * Expands the given input according to the steps in the
     * <a href="http://www.w3.org/TR/json-ld-api/#expansion-algorithm">Expansion
     * algorithm</a>.
     *
     * @param input
     *            The input JSON-LD object.
     * @param opts
     *            The {@link JsonLdOptions} that are to be sent to the expansion
     *            algorithm.
     * @return The expanded JSON-LD document
     * @throws JsonLdError
     *             If there is an error while expanding.
     */
    public static List<Object> expand(Object input, JsonLdOptions opts) throws JsonLdError {
        // 1)
        // TODO: look into java futures/promises

        // 2) TODO: better verification of DOMString IRI
        if (input instanceof String && ((String) input).contains(":")) {
            try {
                final RemoteDocument tmp = opts.getDocumentLoader().loadDocument((String) input);
                input = tmp.getDocument();
                // TODO: figure out how to deal with remote context
            } catch (final Exception e) {
                throw new JsonLdError(Error.LOADING_DOCUMENT_FAILED, e);