Tabnine Logo
ModelUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
ModelUtils
in
org.apache.stanbol.entityhub.servicesapi.util

Best Java code snippets using org.apache.stanbol.entityhub.servicesapi.util.ModelUtils (Showing top 20 results out of 315)

origin: apache/stanbol

@SuppressWarnings("unchecked")
@Override
public void remove(String field, Object parsedValue) {
  if(field == null){
    throw new IllegalArgumentException("The parsed field MUST NOT be NULL");
  } else if(field.isEmpty()){
    throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
  }
  Collection<Object> removeValues = new ArrayList<Object>();
  ModelUtils.checkValues(valueFactory, parsedValue, removeValues);
  Object values = representation.get(field);
  if(values == null) {
    return;
  } else if(removeValues.contains(values)){
    //in case this field has a single value and this values is part of
    //the values to remove -> remove the whole field
    representation.remove(field);
  } else if(values instanceof Collection<?>){
    if(((Collection<Object>)values).removeAll(removeValues) && //remove all Elements
        ((Collection<Object>)values).size()<2){ //if removed check for size
      if(((Collection<Object>)values).size()==1){
        //only one element remaining -> replace the collection with a Object
        representation.put(field, ((Collection<Object>)values).iterator().next());
      } else {
        //if no element remains, remove the field
        representation.remove(field);
      }
    }
  } //else ignore (single value for field && value not to be removed)
}
origin: org.apache.stanbol/org.apache.stanbol.entityhub.core

/**
 * Loads the additional field mappings used by this cache from the yard.
 * This method sets the {@link #baseMapper} field during initialisation.
 * @param yard The yard
 * @param nsPrefixService if present '{prefix}:{localname}' configurations are
 * @return The parsed mappings or <code>null</code> if no found
 * @throws YardException on any Error while reading the {@link Representation}
 * holding the configuration from the {@link Yard}.
 * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}.
 */
protected static FieldMapper loadAdditionalMappings(Yard yard, NamespacePrefixService nsPrefixService) throws YardException {
  if(yard == null){
    throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!");
  }
  Representation addConfig = yard.getRepresentation(Cache.ADDITIONAL_CONFIGURATION_URI);
  if(addConfig != null){
    FieldMapper mapper = readFieldConfig(yard,addConfig, nsPrefixService);
    if(mapper == null){
      log.warn("Invalid Additinal Configuration: Unable to parse FieldMappings from Field "+Cache.FIELD_MAPPING_CONFIG_FIELD+"-> return NULL (no additional Configuration)");
      if(log.isWarnEnabled()){
        log.warn(ModelUtils.getRepresentationInfo(addConfig));
      }
    }
    return mapper;
  } else {
    return null;
  }
}
/**
origin: org.apache.stanbol/org.apache.stanbol.entityhub.servicesapi

/**
 * Copies all elements of the parsed Iterator to a {@link ArrayList}.
 * To use other Set implementations that {@link ArrayList} you can use 
 * {@link #addToCollection(Iterator, Collection)
 * @param <T> the generic type of the returned Collection
 * @param it the Iterator with elements compatible to T
 * @return the collection containing all elements of the iterator
 * @throws IllegalArgumentException if the parsed {@link Iterator} is <code>null</code>
 */
public static <T> Collection<T> asCollection(Iterator<? extends T> it){
  return addToCollection(it, new ArrayList<T>());
}
/**
origin: apache/stanbol

  results = ModelUtils.asCollection(r.get(property.toString()));
} else {
  results = new LinkedHashSet<Object>();
  for(Iterator<String> properties = r.getFieldNames();properties.hasNext();){
    results.addAll(ModelUtils.addToCollection(r.get(properties.next()), results));
origin: apache/stanbol

/**
 * Getter for the id of the Entity the parsed {@link Representation metadata}
 * are {@link RdfResourceEnum#aboutRepresentation about}.
 * @param metadata the metadata
 * @return the id of the entity or <code>null</code> if the parsed {@link Representation}
 * is <code>null</code> or does not define a value for 
 * {@link RdfResourceEnum#aboutRepresentation}
 */
public static String getAboutRepresentation(Representation metadata) throws IllegalStateException{
  if(metadata == null){
    return null;
  }
  Iterator<Reference> refs = metadata.getReferences(RdfResourceEnum.aboutRepresentation.getUri());
  if(refs.hasNext()){
    Reference about = refs.next();
    if(refs.hasNext()){
      log.warn("The parsed Representation {} claims to be the metadata of" +
        "multiple Entities (entities: {})", 
        metadata.getId(),
        asCollection(metadata.getReferences(RdfResourceEnum.aboutRepresentation.getUri())));
    }
    return about.getReference();
  } else {
    return null;
  }
}

origin: apache/stanbol

  /**
   * Appends an URI if possible by using prefix:localName
   * @param builder the StringBuilder to add the URI MUST NOT be NULL
   * @param uri the URI to add MUST NOT be NULL
   */
  private static void appendUri(StringBuilder builder, String uri) {
    String[] namespaceLocal = ModelUtils.getNamespaceLocalName(uri);
    if(namespaceLocal[0]!=null){
      NamespaceEnum namespace = NamespaceEnum.forNamespace(namespaceLocal[0]);
      if(namespace != null){
        builder.append(namespace.getPrefix()).append(':');
      } else {
        builder.append(namespaceLocal[0]);
      }
    } //else no name space to add (e.g. if the pattern is "*")
    builder.append(namespaceLocal[1]);
  }
}
origin: org.apache.stanbol/org.apache.stanbol.entityhub.core

/**
 * Checks if the parsed Entity can be wrapped by this EntityMapping wrapper.
 * Currently it checks only if the rdf:type entityhub:EntityMapping is
 * present
 * @param entity the entity to check
 * @return
 */
public static boolean isValid(Entity entity){
  if(entity != null){
    Set<Reference> types = ModelUtils.asSet(entity.getRepresentation().getReferences(RDF_TYPE));
    return types.contains(ENTITY_MAPPING_TYPE);
  } else {
    return false;
  }
}
/**
origin: org.apache.stanbol/org.apache.stanbol.entityhub.servicesapi

/**
 * Copies all elements of the parsed Iterator to a {@link HashSet}.
 * To use other Set implementations that {@link HashSet} you can use 
 * {@link #addToSet(Iterator, Set)}
 * @param <T> the generic type of the returned set
 * @param it the Iterator with elements compatible to T
 * @return the set containing all elements of the iterator
 * @throws IllegalArgumentException if the parsed {@link Iterator} is <code>null</code>
 */
public static <T> Set<T> asSet(Iterator<? extends T> it){
  if(it == null){
    throw new IllegalArgumentException("The parsed Iterator MUST NOT be NULL!");
  }
  return addToSet(it, new HashSet<T>());
}
/**
origin: org.apache.stanbol/org.apache.stanbol.entityhub.servicesapi

/**
 * Getter for the id of the Entity the parsed {@link Representation metadata}
 * are {@link RdfResourceEnum#aboutRepresentation about}.
 * @param metadata the metadata
 * @return the id of the entity or <code>null</code> if the parsed {@link Representation}
 * is <code>null</code> or does not define a value for 
 * {@link RdfResourceEnum#aboutRepresentation}
 */
public static String getAboutRepresentation(Representation metadata) throws IllegalStateException{
  if(metadata == null){
    return null;
  }
  Iterator<Reference> refs = metadata.getReferences(RdfResourceEnum.aboutRepresentation.getUri());
  if(refs.hasNext()){
    Reference about = refs.next();
    if(refs.hasNext()){
      log.warn("The parsed Representation {} claims to be the metadata of" +
        "multiple Entities (entities: {})", 
        metadata.getId(),
        asCollection(metadata.getReferences(RdfResourceEnum.aboutRepresentation.getUri())));
    }
    return about.getReference();
  } else {
    return null;
  }
}

origin: org.apache.stanbol/org.apache.stanbol.entityhub.core

  /**
   * Appends an URI if possible by using prefix:localName
   * @param builder the StringBuilder to add the URI MUST NOT be NULL
   * @param uri the URI to add MUST NOT be NULL
   */
  private static void appendUri(StringBuilder builder, String uri) {
    String[] namespaceLocal = ModelUtils.getNamespaceLocalName(uri);
    if(namespaceLocal[0]!=null){
      NamespaceEnum namespace = NamespaceEnum.forNamespace(namespaceLocal[0]);
      if(namespace != null){
        builder.append(namespace.getPrefix()).append(':');
      } else {
        builder.append(namespaceLocal[0]);
      }
    } //else no name space to add (e.g. if the pattern is "*")
    builder.append(namespaceLocal[1]);
  }
}
origin: apache/stanbol

/**
 * Checks if the parsed Entity can be wrapped by this EntityMapping wrapper.
 * Currently it checks only if the rdf:type entityhub:EntityMapping is
 * present
 * @param entity the entity to check
 * @return
 */
public static boolean isValid(Entity entity){
  if(entity != null){
    Set<Reference> types = ModelUtils.asSet(entity.getRepresentation().getReferences(RDF_TYPE));
    return types.contains(ENTITY_MAPPING_TYPE);
  } else {
    return false;
  }
}
/**
origin: apache/stanbol

/**
 * Copies all elements of the parsed Iterator to a {@link HashSet}.
 * To use other Set implementations that {@link HashSet} you can use 
 * {@link #addToSet(Iterator, Set)}
 * @param <T> the generic type of the returned set
 * @param it the Iterator with elements compatible to T
 * @return the set containing all elements of the iterator
 * @throws IllegalArgumentException if the parsed {@link Iterator} is <code>null</code>
 */
public static <T> Set<T> asSet(Iterator<? extends T> it){
  if(it == null){
    throw new IllegalArgumentException("The parsed Iterator MUST NOT be NULL!");
  }
  return addToSet(it, new HashSet<T>());
}
/**
origin: org.apache.stanbol/org.apache.stanbol.entityhub.core

@SuppressWarnings("unchecked")
@Override
public void remove(String field, Object parsedValue) {
  if(field == null){
    throw new IllegalArgumentException("The parsed field MUST NOT be NULL");
  } else if(field.isEmpty()){
    throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
  }
  Collection<Object> removeValues = new ArrayList<Object>();
  ModelUtils.checkValues(valueFactory, parsedValue, removeValues);
  Object values = representation.get(field);
  if(values == null) {
    return;
  } else if(removeValues.contains(values)){
    //in case this field has a single value and this values is part of
    //the values to remove -> remove the whole field
    representation.remove(field);
  } else if(values instanceof Collection<?>){
    if(((Collection<Object>)values).removeAll(removeValues) && //remove all Elements
        ((Collection<Object>)values).size()<2){ //if removed check for size
      if(((Collection<Object>)values).size()==1){
        //only one element remaining -> replace the collection with a Object
        representation.put(field, ((Collection<Object>)values).iterator().next());
      } else {
        //if no element remains, remove the field
        representation.remove(field);
      }
    }
  } //else ignore (single value for field && value not to be removed)
}
origin: apache/stanbol

/**
 * Loads the additional field mappings used by this cache from the yard.
 * This method sets the {@link #baseMapper} field during initialisation.
 * @param yard The yard
 * @param nsPrefixService if present '{prefix}:{localname}' configurations are
 * @return The parsed mappings or <code>null</code> if no found
 * @throws YardException on any Error while reading the {@link Representation}
 * holding the configuration from the {@link Yard}.
 * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}.
 */
protected static FieldMapper loadAdditionalMappings(Yard yard, NamespacePrefixService nsPrefixService) throws YardException {
  if(yard == null){
    throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!");
  }
  Representation addConfig = yard.getRepresentation(Cache.ADDITIONAL_CONFIGURATION_URI);
  if(addConfig != null){
    FieldMapper mapper = readFieldConfig(yard,addConfig, nsPrefixService);
    if(mapper == null){
      log.warn("Invalid Additinal Configuration: Unable to parse FieldMappings from Field "+Cache.FIELD_MAPPING_CONFIG_FIELD+"-> return NULL (no additional Configuration)");
      if(log.isWarnEnabled()){
        log.warn(ModelUtils.getRepresentationInfo(addConfig));
      }
    }
    return mapper;
  } else {
    return null;
  }
}
/**
origin: org.apache.stanbol/org.apache.stanbol.entityhub.core

private void deleteMappingsbyTarget(String id) throws YardException {
  if(id != null && !id.isEmpty()){
    FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
    fieldQuery.setConstraint(RdfResourceEnum.mappingTarget.getUri(), new ReferenceConstraint(id));
    deleteEntities(ModelUtils.asCollection(
      entityhubYard.findReferences(fieldQuery).iterator()));
  }
}
origin: org.apache.stanbol/org.apache.stanbol.entityhub.servicesapi

/**
 * This Method uses {@link #getNamespaceLocalName(String)} to split up
 * namespace and local name. It uses also the Data in the
 * {@link NamespaceEnum} to retrieve prefixes for Namespaces.
 * @param uri the URI
 * @return the QName
 */
public static QName getQName(String uri){
  String[] nsln = getNamespaceLocalName(uri);
  if(nsln[0] != null){
    NamespaceEnum entry = NamespaceEnum.forNamespace(nsln[0]);
    if(entry != null){
      return new QName(nsln[0], nsln[1],entry.getPrefix());
    } else {
      return new QName(nsln[0], nsln[1]);
    }
  } else {
    return new QName(nsln[1]);
  }
}
/**
origin: apache/stanbol

/**
 * Copies all elements of the parsed Iterator to a {@link ArrayList}.
 * To use other Set implementations that {@link ArrayList} you can use 
 * {@link #addToCollection(Iterator, Collection)
 * @param <T> the generic type of the returned Collection
 * @param it the Iterator with elements compatible to T
 * @return the collection containing all elements of the iterator
 * @throws IllegalArgumentException if the parsed {@link Iterator} is <code>null</code>
 */
public static <T> Collection<T> asCollection(Iterator<? extends T> it){
  return addToCollection(it, new ArrayList<T>());
}
/**
origin: apache/stanbol

if(expectedFields != null){ //validate fields
  for(String field : expectedFields){
    Set<Object> expectedFieldValues = ModelUtils.asSet(
        data.representations.get(result.getId()).get(field));
    Iterator<Object> fieldValues = result.get(field);
origin: org.apache.stanbol/org.apache.stanbol.entityhub.core

ModelUtils.checkValues(valueFactory, parsedValue, newValues);
Object values = representation.get(field);
if(values != null){
origin: apache/stanbol

fieldMapper.applyMappings(rep, clerezzaRep, valueFactory);
  if(log.isTraceEnabled()){
  log.trace("dereferenced via Mappings {}", ModelUtils.getRepresentationInfo(clerezzaRep));
org.apache.stanbol.entityhub.servicesapi.utilModelUtils

Javadoc

Utilities useful for implementations of the Entityhub Model

Most used methods

  • asCollection
    Copies all elements of the parsed Iterator to a ArrayList. To use other Set implementations that Arr
  • checkValues
    Processes a value parsed as object to the representation. This processing includes: * Removal of nu
  • getRepresentationInfo
    String representation of the parsed Representation inteded for DEBUG level loggings.
  • addToCollection
    Adds the elements of the Iterator to the parsed Collection
  • getNamespaceLocalName
    Splits up a URI in local name and namespace based on the following rules * If URI starts with "u
  • asSet
    Copies all elements of the parsed Iterator to a HashSet. To use other Set implementations that HashS
  • addToSet
    Adds the elements of the Iterator to the parsed Set
  • getAboutRepresentation
    Getter for the id of the Entity the parsed Representationare RdfResourceEnum#aboutRepresentation.
  • randomUUID
    TODO: Maybe we need a better way to generate unique IDs

Popular in Java

  • Finding current android device location
  • scheduleAtFixedRate (Timer)
  • setScale (BigDecimal)
  • onCreateOptionsMenu (Activity)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now