IRI Expansion Algorithm

http://json-ld.org/spec/latest/json-ld-api/#iri-expansion

@param value
@param relative
@param vocab
@param context
@param defined
@return
@throws JsonLdError
545340
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;
    }
362450
public JSONStringer value(boolean value) throws JSONException {
		if (this.stack.isEmpty()) {
			throw new JSONException("Nesting problem");
		}
		beforeValue();
		this.out.append(value);
		return this;
	}
1074413
public Object execute(final Object value, final CsvContext context) {
		validateInputNotNull(value, context);
		if (!(value instanceof String)) {
			throw new SuperCsvCellProcessorException(String.class, value,
					context, this);
		}

		final String string = (String) value;
		final T result;
		try {
			if (formatter != null) {
				result = parse(string, formatter);
			} else {
				result = parse(string);
			}
		} catch (IllegalArgumentException e) {
			throw new SuperCsvCellProcessorException("Failed to parse value",
					context, this, e);
		}

		return next.execute(result, context);
	}
1030914
def vocab_from_json(path: str, encoding: str = C.VOCAB_ENCODING) -> Vocab:
    
    with open(path, encoding=encoding) as inp:
        vocab = json.load(inp)
        utils.check_condition(is_valid_vocab(vocab), "Vocabulary %s not valid." % path)
        logger.info('Vocabulary (%d words) loaded from "%s"', len(vocab), path)
        return vocab
314239
@com.fasterxml.jackson.annotation.JsonProperty("Context")
    public void setContext(String context) {
        this.context = context;
    }
1122176
private void parseLanguageMatchingFix(JsonObject root) {
    JsonObject node = resolve(root, "supplemental", "languageMatching", "written_new");
    JsonArray matches = node.getAsJsonArray("languageMatch");
    for (JsonElement element : matches) {
      JsonObject value = (JsonObject) element;
      String desired = string(value, "desired");
      String supported = string(value, "supported");
      Integer distance = Integer.parseInt(string(value, "distance"));
      boolean oneway = string(value, "oneway", null) != null;
      
      LanguageMatch match = new LanguageMatch(desired, supported, distance, oneway);
      languageMatching.languageMatches.add(match);
    }
    
    JsonObject variables = resolve(node, "matchVariable");
    for (Map.Entry<String, JsonElement> entry : variables.entrySet()) {
      String value = entry.getValue().getAsString();
      languageMatching.matchVariables.add(Pair.pair(entry.getKey(), value));
    }
    
    for (String code : string(node, "paradigmLocales").split("\\s+")) {
      languageMatching.paradigmLocales.add(code);
    }
  }
1291916
protected void addContextTerms(SparseDoubleVector meaning,
                                   Queue<String> words,
                                   int distance) {
        // Iterate through the words in the context.
        for (String term : words) {
            if (!term.equals(IteratorFactory.EMPTY_TOKEN)) {

                // If in read only mode, ignore any terms that are not already in the
                // index map.
                if (readOnly && !indexMap.containsKey(term))
                    continue;

                // Get the index vector for the word.
                TernaryVector termVector = indexMap.get(term);
                if (termVector == null)
                    continue;
                
                // Permute the index vector if a permutation function is provided.
                if (permFunc != null)
                        termVector = permFunc.permute(termVector, distance);

                // Add the index vector and update the distance.
                add(meaning, termVector);
                ++distance;
            }
        }
    }
1143661
public JsonWriter valueLiteral(CharSequence value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writer.write(value.toString());
        }
        return this;
    }
245299
public static PactDslJsonArray arrayEachLike(Integer numberExamples, PactDslJsonRootValue value) {
    PactDslJsonArray parent = new PactDslJsonArray("", "", null, true);
    parent.setNumberExamples(numberExamples);
    parent.matchers.addRule("", parent.matchMin(0));
    parent.putObject(value);
    return parent;
  }
1193424
@SuppressWarnings("unchecked")
	public <T> T defineContextualValue(String key, Object value) {
		return (T) this.values.put(key,  value);
	}
708126
public Object execute(final Object value, final CsvContext context) {
		validateInputNotNull(value, context);
		
		final Double result;
		if( value instanceof Double ) {
			result = (Double) value;
		} else {
			try {
				result = Double.parseDouble(value.toString());
			}
			catch(final NumberFormatException e) {
				throw new SuperCsvCellProcessorException(String.format("'%s' could not be parsed as a Double", value),
					context, this, e);
			}
		}
		
		if( result < min || result > max ) {
			throw new SuperCsvConstraintViolationException(String.format(
				"%f does not lie between the min (%f) and max (%f) values (inclusive)", result, min, max), context,
				this);
		}
		
		return next.execute(result, context);
	}
269286
public static JsonNode toNode(String value, ObjectMapper mapper) {
		try {
			return mapper.readTree(value);
		} catch (IOException ex) {
			throw new FacebookException(ex);
		}
	}
300265
public Object execute(final Object value, final CsvContext context) {
		validateInputNotNull(value, context);
		
		if( !(value instanceof Number) ) {
			throw new SuperCsvCellProcessorException(Number.class, value, context, this);
		}
		
		// create a new DecimalFormat if one is not supplied
		final DecimalFormat decimalFormatter;
		try {
			decimalFormatter = formatter != null ? formatter : new DecimalFormat(decimalFormat);
		}
		catch(IllegalArgumentException e) {
			throw new SuperCsvCellProcessorException(
				String.format("'%s' is not a valid decimal format", decimalFormat), context, this, e);
		}
		
		final String result = decimalFormatter.format(value);
		return next.execute(result, context);
	}
72493
def expand_relative_uri(self, context, uri):
        
        full_uri = urljoin(context, uri)
        if (full_uri != uri):
            print("  WARNING - expanded relative URI to %s" % (full_uri))
            uri = full_uri
        return(uri)
74827
private void updateLocale(final Instance _localeInst,
                              final String _value)
    {
        try {
            final Update update = new Update(_localeInst);
            update.add("Value", _value);
            update.execute();
        } catch (final EFapsException e) {
            DBPropertiesUpdate.LOG.error("updateLocale(String, String)", e);
        }
    }
1138904
public PactDslJsonArray eachLike(PactDslJsonRootValue value, int numberExamples) {
    if (numberExamples == 0) {
      throw new IllegalArgumentException("Testing Zero examples is unsafe. Please make sure to provide at least one " +
        "example in the Pact provider implementation. See https://github.com/DiUS/pact-jvm/issues/546");
    }

    matchers.addRule(rootPath + appendArrayIndex(1), matchMin(0));
    PactDslJsonArray parent = new PactDslJsonArray(rootPath, "", this, true);
    parent.setNumberExamples(numberExamples);
    parent.putObject(value);
    return (PactDslJsonArray) parent.closeArray();
  }
1153277
public Object execute(final Object value, final CsvContext context) {
		validateInputNotNull(value, context);
		
		final String stringValue = value.toString();
		final String result;
		if( stringValue.length() <= maxSize ) {
			result = stringValue;
		} else {
			result = stringValue.substring(0, maxSize) + suffix;
		}
		
		return next.execute(result, context);
	}