tasks/rdfstore/index.js
function(ctx, iri, usedCtx)
{
   var rval = null;
   
   // check the context for a term that could shorten the IRI
   // (give preference to terms over prefixes)
   for(var key in ctx)
   {
      // skip special context keys (start with '@')
      if(key.length > 0 && key[0] !== '@')
      {
         // compact to a term
         if(iri === _getTermIri(ctx, key))
         {
            rval = key;
            if(usedCtx !== null)
            {
               usedCtx[key] = _clone(ctx[key]);
            }
            break;
         }
      }
   }
   
   // term not found, if term is @type, use keyword
   if(rval === null && iri === '@type')
   {
      rval = _getKeywords(ctx)['@type'];
   }
   
   // term not found, check the context for a prefix
   if(rval === null)
   {
      for(var key in ctx)
      {
         // skip special context keys (start with '@')
         if(key.length > 0 && key[0] !== '@')
         {
            // see if IRI begins with the next IRI from the context
            var ctxIri = _getTermIri(ctx, key);
            if(ctxIri !== null)
            {
               var idx = iri.indexOf(ctxIri);
               
               // compact to a prefix
               if(idx === 0 && iri.length > ctxIri.length)
               {
                  rval = key + ':' + iri.substr(ctxIri.length);
                  if(usedCtx !== null)
                  {
                     usedCtx[key] = _clone(ctx[key]);
                  }
                  break;
               }
            }
         }
      }
   }

   // could not compact IRI
   if(rval === null)
   {
      rval = iri;
   }

   return rval;
}
function(ctx, iri, usedCtx)
{
   var rval = null;
   
   // check the context for a term that could shorten the IRI
   // (give preference to terms over prefixes)
   for(var key in ctx)
   {
      // skip special context keys (start with '@')
      if(key.length > 0 && key[0] !== '@')
      {
         // compact to a term
         if(iri === _getTermIri(ctx, key))
         {
            rval = key;
            if(usedCtx !== null)
            {
               usedCtx[key] = _clone(ctx[key]);
            }
            break;
         }
      }
   }
   
   // term not found, if term is @type, use keyword
   if(rval === null && iri === '@type')
   {
      rval = _getKeywords(ctx)['@type'];
   }
   
   // term not found, check the context for a prefix
   if(rval === null)
   {
      for(var key in ctx)
      {
         // skip special context keys (start with '@')
         if(key.length > 0 && key[0] !== '@')
         {
            // see if IRI begins with the next IRI from the context
            var ctxIri = _getTermIri(ctx, key);
            if(ctxIri !== null)
            {
               var idx = iri.indexOf(ctxIri);
               
               // compact to a prefix
               if(idx === 0 && iri.length > ctxIri.length)
               {
                  rval = key + ':' + iri.substr(ctxIri.length);
                  if(usedCtx !== null)
                  {
                     usedCtx[key] = _clone(ctx[key]);
                  }
                  break;
               }
            }
         }
      }
   }

   // could not compact IRI
   if(rval === null)
   {
      rval = iri;
   }

   return rval;
}
function ( ctx , iri , usedCtx ) { var rval = null ; // check the context for a term that could shorten the IRI // (give preference to terms over prefixes) for ( var key in ctx ) { // skip special context keys (start with '@') if ( key . length > 0 && key [ 0 ] !== '@' ) { // compact to a term if ( iri === _getTermIri ( ctx , key ) ) { rval = key ; if ( usedCtx !== null ) { usedCtx [ key ] = _clone ( ctx [ key ] ) ; } break ; } } } // term not found, if term is @type, use keyword if ( rval === null && iri === '@type' ) { rval = _getKeywords ( ctx ) [ '@type' ] ; } // term not found, check the context for a prefix if ( rval === null ) { for ( var key in ctx ) { // skip special context keys (start with '@') if ( key . length > 0 && key [ 0 ] !== '@' ) { // see if IRI begins with the next IRI from the context var ctxIri = _getTermIri ( ctx , key ) ; if ( ctxIri !== null ) { var idx = iri . indexOf ( ctxIri ) ; // compact to a prefix if ( idx === 0 && iri . length > ctxIri . length ) { rval = key + ':' + iri . substr ( ctxIri . length ) ; if ( usedCtx !== null ) { usedCtx [ key ] = _clone ( ctx [ key ] ) ; } break ; } } } } } // could not compact IRI if ( rval === null ) { rval = iri ; } return rval ; }
Compacts an IRI into a term or prefix if it can be. IRIs will not be
compacted to relative IRIs if they match the given context's default
vocabulary.

@param ctx the context to use.
@param iri the IRI to compact.
@param usedCtx a context to update if a value was used from "ctx".

@return the compacted IRI as a term or prefix or the original IRI.
Compacts an IRI into a term or prefix if it can be . IRIs will not be compacted to relative IRIs if they match the given context s default vocabulary .