use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class AnalyzerFactory method register.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void register(String name, String classPath) {
ClassLoader classLoader = SerializerFactory.class.getClassLoader();
Class<?> clazz;
try {
clazz = classLoader.loadClass(classPath);
} catch (Exception e) {
throw new HugeException("Load class path '%s' failed", e, classPath);
}
// Check subclass
if (!Analyzer.class.isAssignableFrom(clazz)) {
throw new HugeException("Class '%s' is not a subclass of " + "class Analyzer", classPath);
}
// Check exists
if (analyzers.containsKey(name)) {
throw new HugeException("Exists analyzer: %s(%s)", name, analyzers.get(name).getName());
}
// Register class
analyzers.put(name, (Class) clazz);
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class JcsegAnalyzer method segment.
@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;
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class RelationshipManager method save.
private Id save(T relationship, boolean expectExists) {
if (!this.graph().existsEdgeLabel(relationship.label())) {
throw new HugeException("Schema is missing for %s '%s'", relationship.label(), relationship.source());
}
HugeVertex source = this.newVertex(relationship.source(), relationship.sourceLabel());
HugeVertex target = this.newVertex(relationship.target(), relationship.targetLabel());
HugeEdge edge = source.constructEdge(relationship.label(), target, relationship.asArray());
E.checkArgument(this.exists(edge.id()) == expectExists, "Can't save %s '%s' that %s exists", this.unhideLabel(), edge.id(), expectExists ? "not" : "already");
this.tx().addEdge(edge);
this.commitOrRollback();
return edge.id();
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class MMSeg4JAnalyzer method segment.
@Override
public Set<String> segment(String text) {
Set<String> result = InsertionOrderUtil.newSet();
MMSeg mmSeg = new MMSeg(new StringReader(text), this.seg);
try {
Word word = null;
while ((word = mmSeg.next()) != null) {
result.add(word.getString());
}
} catch (Exception e) {
throw new HugeException("MMSeg4j segment text '%s' failed", e, text);
}
return result;
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class IKAnalyzer method segment.
@Override
public Set<String> segment(String text) {
Set<String> result = InsertionOrderUtil.newSet();
IKSegmenter ik = new IKSegmenter(new StringReader(text), this.smartSegMode);
try {
Lexeme word = null;
while ((word = ik.next()) != null) {
result.add(word.getLexemeText());
}
} catch (Exception e) {
throw new HugeException("IKAnalyzer segment text '%s' failed", e, text);
}
return result;
}
Aggregations