protected void documentDone(CAS cas) { // TODO: Create confidence FS // contains String name type // contains Double prob if (documentConfidenceType != null) { FeatureStructure confidenceFS = cas.createFS(documentConfidenceType); confidenceFS.setDoubleValue(documentConfidenceFeature, documentConfidence.mean()); confidenceFS.setStringValue(documentConfidenceNameTypeFeature, mNameType.getName()); cas.addFsToIndexes(confidenceFS); } // Clears the adaptive data which was created for the current document mNameFinder.clearAdaptiveData(); documentConfidence = new Mean(); }
private void setValue(AnnotationFS target, String value) { FeatureStructure curElemAnno = target; for (int i = 0; i < featurePath.size() - 1; i++) { FeatureStructure featValue = curElemAnno.getFeatureValue(featurePath.get(i)); curElemAnno = featValue; } Feature lastFeature = featurePath.get(featurePath.size() - 1); curElemAnno.setStringValue(lastFeature, value); }
@Override public boolean containsKey(Object key) { if (!(key instanceof String)) { return false; } FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, (String) key); return metadataIndex.contains(check); } }
@Nullable @Override public String get(Object key) { if (!(key instanceof String)) { return null; } FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, (String) key); FeatureStructure fs = metadataIndex.find(check); return fs.getStringValue(valueFeature); }
@Nullable @Override public String put(String key, String value) { FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, key); FeatureStructure fs = metadataIndex.find(check); String existing = null; if (fs != null) { existing = fs.getStringValue(valueFeature); metadataCas.removeFsFromIndexes(fs); } else { fs = check; } fs.setStringValue(valueFeature, value); metadataCas.addFsToIndexes(fs); return existing; }
aFS.setStringValue(aFeature, aValue == null ? null : aValue.toString()); break; case CAS.TYPE_NAME_BOOLEAN:
public static <T extends FeatureStructure> T createStringList(CAS aCas, Collection<String> aValues) { if (aValues == null) { return null; } TypeSystem ts = aCas.getTypeSystem(); Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_STRING_LIST); if (aValues.size() == 0) { return aCas.createFS(emptyType); } Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST); Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD); Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL); FeatureStructure head = aCas.createFS(nonEmptyType); FeatureStructure list = head; Iterator<String> i = aValues.iterator(); while (i.hasNext()) { head.setStringValue(headFeature, i.next()); if (i.hasNext()) { FeatureStructure tail = aCas.createFS(nonEmptyType); head.setFeatureValue(tailFeature, tail); head = tail; } else { head.setFeatureValue(tailFeature, aCas.createFS(emptyType)); } } return (T) list; }
/** * Sets the feature value based on the type that you're using to set, make sure that your * primitives are casted to the right type. * * @param name the feature name * @param value the value to set */ public void setFeatureValue(String name, @Nullable Object value) { Feature feature = getFeature(name); if (value instanceof String) { featureStructure.setStringValue(feature, (String) value); } else if (value instanceof Integer) { featureStructure.setIntValue(feature, ((Integer) value)); } else if (value instanceof Long) { featureStructure.setLongValue(feature, ((Long) value)); } else if (value instanceof Double) { featureStructure.setDoubleValue(feature, ((Double) value)); } else if (value instanceof Float) { featureStructure.setFloatValue(feature, ((Float) value)); } else if (value instanceof FeatureStructure) { featureStructure.setFeatureValue(feature, ((FeatureStructure) value)); } else if (value instanceof Byte) { featureStructure.setByteValue(feature, ((Byte) value)); } }
idFS.setStringValue(idFeature, casId); cas.addFsToIndexes(idFS);
protected void documentDone(CAS cas) { // TODO: Create confidence FS // contains String name type // contains Double prob if (documentConfidenceType != null) { FeatureStructure confidenceFS = cas.createFS(documentConfidenceType); confidenceFS.setDoubleValue(documentConfidenceFeature, documentConfidence.mean()); confidenceFS.setStringValue(documentConfidenceNameTypeFeature, mNameType.getName()); cas.addFsToIndexes(confidenceFS); } // Clears the adaptive data which was created for the current document mNameFinder.clearAdaptiveData(); documentConfidence = new Mean(); }
private static void setLinkFeature(FeatureStructure aFS, AnnotationFeature aFeature, List<LinkWithRoleModel> aValue, Feature feature) { Type linkType = aFS.getCAS().getTypeSystem().getType(aFeature.getLinkTypeName()); Feature roleFeat = linkType.getFeatureByBaseName(aFeature .getLinkTypeRoleFeatureName()); Feature targetFeat = linkType.getFeatureByBaseName(aFeature .getLinkTypeTargetFeatureName()); // Create all the links // FIXME: actually we could re-use existing link link feature structures List<FeatureStructure> linkFSes = new ArrayList<>(); if (aValue != null) { // remove duplicate links Set<LinkWithRoleModel> links = new HashSet<>(aValue); for (LinkWithRoleModel e : links) { // Skip links that have been added in the UI but where the target has not // yet been // set if (e.targetAddr == -1) { continue; } FeatureStructure link = aFS.getCAS().createFS(linkType); link.setStringValue(roleFeat, e.role); link.setFeatureValue(targetFeat, selectByAddr(aFS.getCAS(), e.targetAddr)); linkFSes.add(link); } } setLinkFeatureValue(aFS, feature, linkFSes); }
private static void setLinkFeature(FeatureStructure aFS, AnnotationFeature aFeature, List<LinkWithRoleModel> aValue, Feature feature) { Type linkType = aFS.getCAS().getTypeSystem().getType(aFeature.getLinkTypeName()); Feature roleFeat = linkType.getFeatureByBaseName(aFeature .getLinkTypeRoleFeatureName()); Feature targetFeat = linkType.getFeatureByBaseName(aFeature .getLinkTypeTargetFeatureName()); // Create all the links // FIXME: actually we could re-use existing link link feature structures List<FeatureStructure> linkFSes = new ArrayList<>(); if (aValue != null) { // remove duplicate links Set<LinkWithRoleModel> links = new HashSet<>(aValue); for (LinkWithRoleModel e : links) { // Skip links that have been added in the UI but where the target has not // yet been // set if (e.targetAddr == -1) { continue; } FeatureStructure link = aFS.getCAS().createFS(linkType); link.setStringValue(roleFeat, e.role); link.setFeatureValue(targetFeat, selectByAddr(aFS.getCAS(), e.targetAddr)); linkFSes.add(link); } } setLinkFeatureValue(aFS, feature, linkFSes); }
public void annotationAdded(AnnotationFS annotation, RuleMatch creator) { CAS cas = annotation.getCAS(); Type t = cas.getTypeSystem().getType(TYPE); Feature featureRule = t.getFeatureByBaseName(FEATURE_RULE); Feature featureAnnotation = t.getFeatureByBaseName(FEATURE_ANNOTATION); Feature featureScript = t.getFeatureByBaseName(FEATURE_SCRIPT); Feature featureId = t.getFeatureByBaseName(FEATURE_ID); String ruleString = "provided"; String ruleScript = ""; int ruleId = -1; if (creator != null) { ruleString = verbalizer.verbalize(creator.getRule()); ruleId = creator.getRule().getId(); ruleScript = creator.getRule().getParent().getScript().getRootBlock().getNamespace(); } FeatureStructure fs = cas.createFS(t); fs.setStringValue(featureRule, ruleString); fs.setFeatureValue(featureAnnotation, annotation); fs.setIntValue(featureId, ruleId); fs.setStringValue(featureScript, ruleScript); fsList.add(fs); }
@Override public void annotationAdded(AnnotationFS annotation, AbstractRuleMatch<? extends AbstractRule> creator) { CAS cas = annotation.getCAS(); Type t = cas.getTypeSystem().getType(TYPE); Feature featureRule = t.getFeatureByBaseName(FEATURE_RULE); Feature featureAnnotation = t.getFeatureByBaseName(FEATURE_ANNOTATION); Feature featureScript = t.getFeatureByBaseName(FEATURE_SCRIPT); Feature featureId = t.getFeatureByBaseName(FEATURE_ID); String ruleString = "provided"; String ruleScript = ""; int ruleId = -1; if (creator != null) { ruleString = verbalizer.verbalize(creator.getRule()); ruleId = creator.getRule().getId(); ruleScript = creator.getRule().getParent().getScript().getRootBlock().getNamespace(); } FeatureStructure fs = cas.createFS(t); fs.setStringValue(featureRule, ruleString); fs.setFeatureValue(featureAnnotation, annotation); fs.setIntValue(featureId, ruleId); fs.setStringValue(featureScript, ruleScript); fsList.add(fs); }
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas, String artifactID ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.createView("metadata"); metadataCas.setDocumentText(""); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); this.artifactID = artifactID; FeatureStructure documentIdFs = metadataCas.createFS(idType); documentIdFs.setStringValue(idFeat, artifactID); metadataCas.addFsToIndexes(documentIdFs); metadataIndex = metadataCas.getIndexRepository().getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }
public static void setFeature(FeatureStructure aFS, String aFeature, String... aValue) { Feature feat = getMandatoryFeature(aFS, aFeature); if (feat.getRange().isPrimitive()) { requireSingleValue(feat, aValue); aFS.setStringValue(feat, aValue[0]); } else if (aValue == null) { aFS.setFeatureValue(feat, null); } else if (feat.getRange().isArray()) { aFS.setFeatureValue(feat, createStringArray(aFS.getCAS(), aValue)); } else { aFS.setFeatureValue(feat, createStringList(aFS.getCAS(), aValue)); } }
CASArtifact( @Nullable LabelAdapters labelAdapters, Artifact artifact, CAS cas ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.createView("metadata"); metadataCas.setDocumentText(""); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); this.artifactID = artifact.getArtifactID(); FeatureStructure documentIdFs = metadataCas.createFS(idType); documentIdFs.setStringValue(idFeat, artifactID); metadataCas.addFsToIndexes(documentIdFs); metadataIndex = metadataCas.getIndexRepository().getIndex("metadata", metadataType); casMetadata = new CASMetadata(); casMetadata.putAll(artifact.getMetadata()); copyDocuments(artifact); }
private static FeatureStructure makeLinkFS(JCas aJCas, String aType, String aSlotLabel, AnnotationFS aTarget) { Type linkType = aJCas.getTypeSystem().getType(aType); FeatureStructure linkA1 = aJCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), aTarget); aJCas.getCas().addFsToIndexes(linkA1); return linkA1; }
public static FeatureStructure makeLinkFS(JCas aJCas, String aSlotLabel, int aTargetBegin, int aTargetEnd) { Token token1 = new Token(aJCas, aTargetBegin, aTargetEnd); token1.addToIndexes(); Type linkType = aJCas.getTypeSystem().getType(LINK_TYPE); FeatureStructure linkA1 = aJCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), token1); aJCas.getCas().addFsToIndexes(linkA1); return linkA1; } }
public static FeatureStructure makeLinkFS(JCas aJCas, String aSlotLabel, int aTargetBegin, int aTargetEnd) { Token token1 = new Token(aJCas, aTargetBegin, aTargetEnd); token1.addToIndexes(); Type linkType = aJCas.getTypeSystem().getType(LINK_TYPE); FeatureStructure linkA1 = aJCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), token1); aJCas.getCas().addFsToIndexes(linkA1); return linkA1; } }