Java Code Examples for com.baidu.hugegraph.util.InsertionOrderUtil#newSet()

The following examples show how to use com.baidu.hugegraph.util.InsertionOrderUtil#newSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmartCNAnalyzer.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public Set<String> segment(String text) {
    Set<String> result = InsertionOrderUtil.newSet();
    Reader reader = new StringReader(text);
    try (TokenStream tokenStream = ANALYZER.tokenStream("text", reader)) {
        tokenStream.reset();
        CharTermAttribute term = null;
        while (tokenStream.incrementToken()) {
            term = tokenStream.getAttribute(CharTermAttribute.class);
            result.add(term.toString());
        }
    } catch (Exception e) {
        throw new HugeException("SmartCN segment text '%s' failed",
                                e, text);
    }
    return result;
}
 
Example 2
Source File: HbaseTable.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
protected <R> R queryByIds(HbaseSession<R> session, Set<Id> ids) {
    Set<byte[]> rowkeys = InsertionOrderUtil.newSet();
    for (Id id : ids) {
        rowkeys.add(id.asBytes());
    }
    return session.get(this.table(), null, rowkeys);
}
 
Example 3
Source File: CassandraSerializer.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
protected Object toLongSet(Collection<Id> ids) {
    Set<Long> results = InsertionOrderUtil.newSet();
    for (Id id : ids) {
        results.add(id.asLong());
    }
    return results;
}
 
Example 4
Source File: GraphIndexTransaction.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private static Set<IndexLabel> matchRangeOrSearchIndexLabels(
                               ConditionQuery query,
                               Set<IndexLabel> indexLabels) {
    Set<IndexLabel> matchedIndexLabels = InsertionOrderUtil.newSet();
    for (Condition.Relation relation : query.userpropRelations()) {
        if (!relation.relation().isRangeType() &&
            !relation.relation().isSearchType()) {
            continue;
        }
        Id key = (Id) relation.key();
        boolean matched = false;
        for (IndexLabel indexLabel : indexLabels) {
            if (indexLabel.indexType().isRange() ||
                indexLabel.indexType().isSearch()) {
                if (indexLabel.indexField().equals(key)) {
                    matched = true;
                    matchedIndexLabels.add(indexLabel);
                    break;
                }
            }
        }
        if (!matched) {
            return ImmutableSet.of();
        }
    }
    return matchedIndexLabels;
}
 
Example 5
Source File: GraphIndexTransaction.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
/**
 * Collect matched IndexLabel(s) in a SchemaLabel for a query
 * @param schemaLabel find indexLabels of this schemaLabel
 * @param query conditions container
 * @return MatchedLabel object contains schemaLabel and matched indexLabels
 */
@Watched(prefix = "index")
private MatchedIndex collectMatchedIndex(SchemaLabel schemaLabel,
                                         ConditionQuery query) {
    SchemaTransaction schema = this.params().schemaTransaction();
    Set<IndexLabel> ils = InsertionOrderUtil.newSet();
    for (Id il : schemaLabel.indexLabels()) {
        IndexLabel indexLabel = schema.getIndexLabel(il);
        if (indexLabel.indexType().isUnique()) {
            continue;
        }
        ils.add(indexLabel);
    }
    if (ils.isEmpty()) {
        return null;
    }
    // Try to match single or composite index
    Set<IndexLabel> matchedILs = matchSingleOrCompositeIndex(query, ils);
    if (matchedILs.isEmpty()) {
        // Try joint indexes
        matchedILs = matchJointIndexes(query, ils);
    }

    if (!matchedILs.isEmpty()) {
        return new MatchedIndex(schemaLabel, matchedILs);
    }
    return null;
}
 
Example 6
Source File: DataTypeUtil.java    From hugegraph-loader with Apache License 2.0 5 votes vote down vote up
/**
 * collection format: "obj1,obj2,...,objn" or "[obj1,obj2,...,objn]" ..etc
 * TODO: After parsing to json, the order of the collection changed
 * in some cases (such as list<date>)
 **/
private static Object parseMultiValues(String key, Object values,
                                       DataType dataType,
                                       Cardinality cardinality,
                                       InputSource source) {
    // JSON file should not parse again
    if (values instanceof Collection &&
        checkCollectionDataType(key, (Collection<?>) values, dataType)) {
        return values;
    }

    E.checkState(values instanceof String,
                 "The value(key='%s') must be String type, but got '%s'(%s)",
                 key, values);
    String rawValue = (String) values;
    List<Object> valueColl = split(key, rawValue, source);
    Collection<Object> results = cardinality == Cardinality.LIST ?
                                 InsertionOrderUtil.newList() :
                                 InsertionOrderUtil.newSet();
    valueColl.forEach(value -> {
        results.add(parseSingleValue(key, value, dataType, source));
    });
    E.checkArgument(checkCollectionDataType(key, results, dataType),
                    "Not all collection elems %s match with data type %s",
                    results, dataType);
    return results;
}
 
Example 7
Source File: HugeTask.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public void depends(Id id) {
    E.checkState(this.status == TaskStatus.NEW,
                 "Can't add dependency in status '%s'", this.status);
    if (this.dependencies == null) {
        this.dependencies = InsertionOrderUtil.newSet();
    }
    this.dependencies.add(id);
}
 
Example 8
Source File: WordAnalyzer.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> segment(String text) {
    Set<String> result = InsertionOrderUtil.newSet();
    List<Word> words = WordSegmenter.segWithStopWords(text, this.algorithm);
    for (Word word : words) {
        result.add(word.getText());
    }
    return result;
}
 
Example 9
Source File: JcsegAnalyzer.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> segment(String text) {
    Set<String> result = InsertionOrderUtil.newSet();
    try {
        Object[] args = new Object[]{new StringReader(text), CONFIG, DIC};
        ISegment seg = SegmentFactory.createJcseg(this.segMode, args);
        IWord word = null;
        while ((word = seg.next()) != null) {
            result.add(word.getValue());
        }
    } catch (Exception e) {
        throw new HugeException("Jcseg segment text '%s' failed", e, text);
    }
    return result;
}
 
Example 10
Source File: ConditionQueryFlatten.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private static Set<Relations> and(Set<Relations> left,
                                  Set<Relations> right) {
    Set<Relations> result = InsertionOrderUtil.newSet();
    for (Relations leftRelations : left) {
        for (Relations rightRelations : right) {
            Relations relations = new Relations();
            relations.addAll(leftRelations);
            relations.addAll(rightRelations);
            result.add(relations);
        }
    }
    return result;
}
 
Example 11
Source File: JiebaAnalyzer.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> segment(String text) {
    Set<String> result = InsertionOrderUtil.newSet();
    for (SegToken token : JIEBA_SEGMENTER.process(text, this.segMode)) {
        result.add(token.word);
    }
    return result;
}
 
Example 12
Source File: FusiformSimilarityTraverser.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public Map<Id, Set<Map<String, Object>>> toMap() {
    Map<Id, Set<Map<String, Object>>> results = new HashMap<>();
    for (Map.Entry<Id, Set<Similar>> entry : this.entrySet()) {
        Id source = entry.getKey();
        Set<Similar> similars = entry.getValue();
        Set<Map<String, Object>> result = InsertionOrderUtil.newSet();
        for (Similar similar : similars) {
            result.add(similar.toMap());
        }
        results.put(source, result);
    }
    return results;
}
 
Example 13
Source File: HugeVertex.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public HugeVertex(final HugeGraph graph, Id id, VertexLabel label) {
    super(graph, id);

    this.tx = null;
    this.vertexLabel(label);
    this.edges = InsertionOrderUtil.newSet();
    this.name = null;
    if (this.id != null) {
        if (label.idStrategy() == IdStrategy.CUSTOMIZE_UUID) {
            this.assignId(id);
        } else {
            this.checkIdLength();
        }
    }
}
 
Example 14
Source File: HugeIndex.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public Set<IdWithExpiredTime> expiredElementIds() {
    long now = this.graph.now();
    Set<IdWithExpiredTime> expired = InsertionOrderUtil.newSet(
                                     this.elementIds.size());
    for (IdWithExpiredTime id : this.elementIds) {
        if (0L < id.expiredTime && id.expiredTime < now) {
            expired.add(id);
        }
    }
    this.elementIds.removeAll(expired);
    return expired;
}
 
Example 15
Source File: HugeIndex.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public Set<Id> elementIds() {
    Set<Id> ids = InsertionOrderUtil.newSet(this.elementIds.size());
    for (IdWithExpiredTime idWithExpiredTime : this.elementIds) {
        ids.add(idWithExpiredTime.id());
    }
    return Collections.unmodifiableSet(ids);
}
 
Example 16
Source File: MysqlSerializer.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
protected Set<Object> parseIndexElemIds(TableBackendEntry entry) {
    Set<Object> elemIds = InsertionOrderUtil.newSet();
    elemIds.add(entry.column(HugeKeys.ELEMENT_IDS));
    for (TableBackendEntry.Row row : entry.subRows()) {
        elemIds.add(row.column(HugeKeys.ELEMENT_IDS));
    }
    return elemIds;
}
 
Example 17
Source File: InputProgress.java    From hugegraph-loader with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public InputProgress(@JsonProperty("type") SourceType type,
                     @JsonProperty("loaded_items")
                     Set<InputItemProgress> loadedItems,
                     @JsonProperty("loading_item")
                     InputItemProgress loadingItem) {
    this.type = type;
    this.loadedItems = loadedItems;
    this.loadingItem = loadingItem;
    this.loadingItems = InsertionOrderUtil.newSet();
}
 
Example 18
Source File: ConditionQueryFlatten.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
private static Set<Relations> or(Set<Relations> left,
                                 Set<Relations> right) {
    Set<Relations> result = InsertionOrderUtil.newSet(left);
    result.addAll(right);
    return result;
}
 
Example 19
Source File: HugeVertex.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public void resetEdges() {
    this.edges = InsertionOrderUtil.newSet();
}
 
Example 20
Source File: InputProgress.java    From hugegraph-loader with Apache License 2.0 4 votes vote down vote up
public InputProgress(InputStruct struct) {
    this.type = struct.input().type();
    this.loadedItems = InsertionOrderUtil.newSet();
    this.loadingItem = null;
    this.loadingItems = InsertionOrderUtil.newSet();
}