String expandIri ( String value , boolean relative , boolean vocab , Map < String , Object > context , Map < String , Boolean > defined ) throws JsonLdError { // 1) if ( value == null || JsonLdUtils . isKeyword ( value ) ) { return value ; } // 2) if ( context != null && context . containsKey ( value ) && ! Boolean . TRUE . equals ( defined . get ( value ) ) ) { this . createTermDefinition ( context , value , defined ) ; } // 3) if ( vocab && this . termDefinitions . containsKey ( value ) ) { final Map < String , Object > td = ( Map < String , Object > ) this . termDefinitions . get ( value ) ; if ( td != null ) { return ( String ) td . get ( JsonLdConsts . ID ) ; } else { return null ; } } // 4) final int colIndex = value . indexOf ( ":" ) ; if ( colIndex >= 0 ) { // 4.1) final String prefix = value . substring ( 0 , colIndex ) ; final String suffix = value . substring ( colIndex + 1 ) ; // 4.2) if ( "_" . equals ( prefix ) || suffix . startsWith ( "//" ) ) { return value ; } // 4.3) if ( context != null && context . containsKey ( prefix ) && ( ! defined . containsKey ( prefix ) || defined . get ( prefix ) == false ) ) { this . createTermDefinition ( context , prefix , defined ) ; } // 4.4) if ( this . termDefinitions . containsKey ( prefix ) ) { return ( String ) ( ( Map < String , Object > ) this . termDefinitions . get ( prefix ) ) . get ( JsonLdConsts . ID ) + suffix ; } // 4.5) return value ; } // 5) if ( vocab && this . containsKey ( JsonLdConsts . VOCAB ) ) { return this . get ( JsonLdConsts . VOCAB ) + value ; } // 6) else if ( relative ) { return JsonLdUrl . resolve ( ( String ) this . get ( JsonLdConsts . BASE ) , value ) ; } else if ( context != null && JsonLdUtils . isRelativeIri ( value ) ) { throw new JsonLdError ( Error . INVALID_IRI_MAPPING , "not an absolute IRI: " + value ) ; } // 7) return value ; }
IRI Expansion Algorithm