public Map<String, Object> getInverse() {

        // lazily create inverse
        if (inverse != null) {
            return inverse;
        }

        // 1)
        inverse = newMap();

        // 2)
        String defaultLanguage = (String) this.get(JsonLdConsts.LANGUAGE);
        if (defaultLanguage == null) {
            defaultLanguage = JsonLdConsts.NONE;
        }

        // create term selections for each mapping in the context, ordererd by
        // shortest and then lexicographically least
        final List<String> terms = new ArrayList<String>(termDefinitions.keySet());
        Collections.sort(terms, new Comparator<String>() {
            @Override
            public int compare(String a, String b) {
                return compareShortestLeast(a, b);
            }
        });

        for (final String term : terms) {
            final Map<String, Object> definition = (Map<String, Object>) termDefinitions.get(term);
            // 3.1)
            if (definition == null) {
                continue;
            }

            // 3.2)
            String container = (String) definition.get(JsonLdConsts.CONTAINER);
            if (container == null) {
                container = JsonLdConsts.NONE;
            }

            // 3.3)
            final String iri = (String) definition.get(JsonLdConsts.ID);

            // 3.4 + 3.5)
            Map<String, Object> containerMap = (Map<String, Object>) inverse.get(iri);
            if (containerMap == null) {
                containerMap = newMap();
                inverse.put(iri, containerMap);
            }

            // 3.6 + 3.7)
            Map<String, Object> typeLanguageMap = (Map<String, Object>) containerMap.get(container);
            if (typeLanguageMap == null) {
                typeLanguageMap = newMap();
                typeLanguageMap.put(JsonLdConsts.LANGUAGE, newMap());
                typeLanguageMap.put(JsonLdConsts.TYPE, newMap());
                containerMap.put(container, typeLanguageMap);
            }

            // 3.8)
            if (Boolean.TRUE.equals(definition.get(JsonLdConsts.REVERSE))) {
                final Map<String, Object> typeMap = (Map<String, Object>) typeLanguageMap
                        .get(JsonLdConsts.TYPE);
                if (!typeMap.containsKey(JsonLdConsts.REVERSE)) {
                    typeMap.put(JsonLdConsts.REVERSE, term);
                }
                // 3.9)
            } else if (definition.containsKey(JsonLdConsts.TYPE)) {
                final Map<String, Object> typeMap = (Map<String, Object>) typeLanguageMap
                        .get(JsonLdConsts.TYPE);
                if (!typeMap.containsKey(definition.get(JsonLdConsts.TYPE))) {
                    typeMap.put((String) definition.get(JsonLdConsts.TYPE), term);
                }
                // 3.10)
            } else if (definition.containsKey(JsonLdConsts.LANGUAGE)) {
                final Map<String, Object> languageMap = (Map<String, Object>) typeLanguageMap
                        .get(JsonLdConsts.LANGUAGE);
                String language = (String) definition.get(JsonLdConsts.LANGUAGE);
                if (language == null) {
                    language = JsonLdConsts.NULL;
                }
                if (!languageMap.containsKey(language)) {
                    languageMap.put(language, term);
                }
                // 3.11)
            } else {
                // 3.11.1)
                final Map<String, Object> languageMap = (Map<String, Object>) typeLanguageMap
                        .get(JsonLdConsts.LANGUAGE);
                // 3.11.2)
                if (!languageMap.containsKey(JsonLdConsts.LANGUAGE)) {
                    languageMap.put(JsonLdConsts.LANGUAGE, term);
                }
                // 3.11.3)
                if (!languageMap.containsKey(JsonLdConsts.NONE)) {
                    languageMap.put(JsonLdConsts.NONE, term);
                }
                // 3.11.4)
                final Map<String, Object> typeMap = (Map<String, Object>) typeLanguageMap
                        .get(JsonLdConsts.TYPE);
                // 3.11.5)
                if (!typeMap.containsKey(JsonLdConsts.NONE)) {
                    typeMap.put(JsonLdConsts.NONE, term);
                }
            }
        }
        // 4)
        return inverse;
    }
public Map < String , Object > getInverse ( ) { if ( inverse != null ) { return inverse ; } inverse = newMap ( ) ; String defaultLanguage = ( String ) this . get ( JsonLdConsts . LANGUAGE ) ; if ( defaultLanguage == null ) { defaultLanguage = JsonLdConsts . NONE ; } final List < String > terms = new ArrayList < String > ( termDefinitions . keySet ( ) ) ; Collections . sort ( terms , new Comparator < String > ( ) { @ Override public int compare ( String a , String b ) { return compareShortestLeast ( a , b ) ; } } ) ; for ( final String term : terms ) { final Map < String , Object > definition = ( Map < String , Object > ) termDefinitions . get ( term ) ; if ( definition == null ) { continue ; } String container = ( String ) definition . get ( JsonLdConsts . CONTAINER ) ; if ( container == null ) { container = JsonLdConsts . NONE ; } final String iri = ( String ) definition . get ( JsonLdConsts . ID ) ; Map < String , Object > containerMap = ( Map < String , Object > ) inverse . get ( iri ) ; if ( containerMap == null ) { containerMap = newMap ( ) ; inverse . put ( iri , containerMap ) ; } Map < String , Object > typeLanguageMap = ( Map < String , Object > ) containerMap . get ( container ) ; if ( typeLanguageMap == null ) { typeLanguageMap = newMap ( ) ; typeLanguageMap . put ( JsonLdConsts . LANGUAGE , newMap ( ) ) ; typeLanguageMap . put ( JsonLdConsts . TYPE , newMap ( ) ) ; containerMap . put ( container , typeLanguageMap ) ; } if ( Boolean . TRUE . equals ( definition . get ( JsonLdConsts . REVERSE ) ) ) { final Map < String , Object > typeMap = ( Map < String , Object > ) typeLanguageMap . get ( JsonLdConsts . TYPE ) ; if ( ! typeMap . containsKey ( JsonLdConsts . REVERSE ) ) { typeMap . put ( JsonLdConsts . REVERSE , term ) ; } } else if ( definition . containsKey ( JsonLdConsts . TYPE ) ) { final Map < String , Object > typeMap = ( Map < String , Object > ) typeLanguageMap . get ( JsonLdConsts . TYPE ) ; if ( ! typeMap . containsKey ( definition . get ( JsonLdConsts . TYPE ) ) ) { typeMap . put ( ( String ) definition . get ( JsonLdConsts . TYPE ) , term ) ; } } else if ( definition . containsKey ( JsonLdConsts . LANGUAGE ) ) { final Map < String , Object > languageMap = ( Map < String , Object > ) typeLanguageMap . get ( JsonLdConsts . LANGUAGE ) ; String language = ( String ) definition . get ( JsonLdConsts . LANGUAGE ) ; if ( language == null ) { language = JsonLdConsts . NULL ; } if ( ! languageMap . containsKey ( language ) ) { languageMap . put ( language , term ) ; } } else { final Map < String , Object > languageMap = ( Map < String , Object > ) typeLanguageMap . get ( JsonLdConsts . LANGUAGE ) ; if ( ! languageMap . containsKey ( JsonLdConsts . LANGUAGE ) ) { languageMap . put ( JsonLdConsts . LANGUAGE , term ) ; } if ( ! languageMap . containsKey ( JsonLdConsts . NONE ) ) { languageMap . put ( JsonLdConsts . NONE , term ) ; } final Map < String , Object > typeMap = ( Map < String , Object > ) typeLanguageMap . get ( JsonLdConsts . TYPE ) ; if ( ! typeMap . containsKey ( JsonLdConsts . NONE ) ) { typeMap . put ( JsonLdConsts . NONE , term ) ; } } } return inverse ; }
Inverse Context Creation

http://json-ld.org/spec/latest/json-ld-api/#inverse-context-creation

Generates an inverse context for use in the compaction algorithm, if not
already generated for the given active context.

@return the inverse context.