private static void writeSemanticType(JsonWriter writer, SemanticType semanticType) throws IOException { if (semanticType == null) return; String nullStr = null; writer.beginObject(); writer.name("hNodeId").value(semanticType.getHNodeId()); writer.name("domain"); if (semanticType.getDomain() == null) writer.value(nullStr); else writeLabel(writer, semanticType.getDomain()); writer.name("type"); if (semanticType.getType() == null) writer.value(nullStr); else writeLabel(writer, semanticType.getType()); writer.name("origin").value(semanticType.getOrigin().toString()); writer.name("confidenceScore").value(semanticType.getConfidenceScore()); writer.endObject(); }
public void setLearnedSemanticTypes(List<SemanticType> learnedSemanticTypes) { double sum = 0.0; // normalizing the confidence scores if (learnedSemanticTypes != null) { for (SemanticType st : learnedSemanticTypes) { sum += st.getConfidenceScore() != null ? st.getConfidenceScore().doubleValue() : 0.0; } double confidence; this.learnedSemanticTypes = new ArrayList<>(); for (SemanticType st : learnedSemanticTypes) { confidence = st.getConfidenceScore() != null ? st.getConfidenceScore() : 0.0; SemanticType semType = new SemanticType(st.getHNodeId(), st.getType(), st.getDomain(), st.getDomainId(), st.isProvenance(), st.getOrigin(), confidence / sum); this.learnedSemanticTypes.add(semType); } } if (this.learnedSemanticTypes != null) Collections.sort(this.learnedSemanticTypes, Collections.reverseOrder()); }
semanticType.getDomain() == null || semanticType.getType() == null) continue; domainUri = semanticType.getDomain().getUri(); propertyUri = semanticType.getType().getUri(); for (SemanticType semanticType: candidateSemanticTypes) { logger.info("\t===== Semantic Type: " + semanticType.getModelLabelString()); semanticType.getDomain() == null || semanticType.getType() == null) continue; domainUri = semanticType.getDomain().getUri(); propertyUri = semanticType.getType().getUri(); Integer countOfSemanticType = semanticTypesCount.get(domainUri + propertyUri);
private void writeType(SemanticType type, JSONWriter writer, Map<String, ColumnNode> hNodeIdTocolumnNodeMap) { if (type != null && type.getConfidenceLevel() != SemanticType.ConfidenceLevel.Low) { ColumnNode alignmentColumnNode = hNodeIdTocolumnNodeMap.get(type.getHNodeId()); .value(type.getOrigin().name()) .key(JsonKeys.ConfidenceLevel.name()) .value(type.getConfidenceLevel().name()) .key(JsonKeys.isPrimary.name()) .value(true); String index = type.getDomainId().substring(type.getDomain().getUri().length()); String domainDisplayLabel = type.getDomain().getDisplayName() + index; if (!type.isClass()) { writer .key(JsonKeys.FullType.name()).value(type.getType().getUri()) .key(JsonKeys.DisplayLabel.name()).value(type.getType().getDisplayName()) .key(JsonKeys.DisplayRDFSLabel.name()).value(type.getType().getRdfsLabel()) .key(JsonKeys.DisplayRDFSComment.name()).value(type.getType().getRdfsComment()) .key(JsonKeys.DomainId.name()).value(type.getDomainId()) .key(JsonKeys.DomainUri.name()).value(type.getDomain().getUri()) .key(JsonKeys.DisplayDomainLabel.name()).value(domainDisplayLabel) .key(JsonKeys.DomainRDFSLabel.name()).value(type.getDomain().getRdfsLabel()) .key(JsonKeys.DomainRDFSComment.name()).value(type.getDomain().getRdfsComment()) .key(JsonKeys.isProvenance.name()).value(type.isProvenance()) .key(JsonKeys.FullType.name()).value(type.getDomainId()) .key(JsonKeys.DisplayLabel.name()).value(domainDisplayLabel) .key(JsonKeys.DisplayRDFSLabel.name()).value(type.getDomain().getRdfsLabel()) .key(JsonKeys.DisplayRDFSComment.name()).value(type.getDomain().getRdfsComment())
boolean lngFound = false; for (SemanticType type : worksheet.getSemanticTypes().getListOfTypes()) { if (type.getType().getUri().equals(SRID_PROPERTY) && type.getDomain().getUri().equals(SRID_CLASS)){ if (type.getType().getUri().equals(WGS84_LAT_PROPERTY) && type.getDomain().getUri().equals(POINT_CLASS)) { coordinateHNodeIds.add(type.getHNodeId()); populatePoints(coordinateHNodeIds, currentCase, getRows(), getColumnMap()); coordinateHNodeIds.add(type.getHNodeId()); latFound = true; else if (type.getType().getUri().equals(WGS84_LNG_PROPERTY) && type.getDomain().getUri().equals(POINT_CLASS)) { coordinateHNodeIds.set(0, type.getHNodeId()); currentCase = CoordinateCase.POINT_LAT_LNG; populatePoints(coordinateHNodeIds, currentCase, getRows(), coordinateHNodeIds.clear(); } else { coordinateHNodeIds.add(type.getHNodeId()); lngFound = true; else if (type.getType().getUri().equals(POINT_POS_PROPERTY) && type.getDomain().getUri().equals(POINT_CLASS)) {
HashMap<String, SemanticType> semanticIdMap = new HashMap<>(); for(SemanticType type : oldSemanticTypes) { String semId = LinkIdFactory.getLinkId(type.getType().getUri(), type.getDomainId(), type.getHNodeId()); semanticIdMap.put(semId, type);
semanticType.getDomain() == null || semanticType.getType() == null) continue; domainUri = semanticType.getDomain().getUri(); propertyUri = semanticType.getType().getUri(); for (SemanticType semanticType: candidateSemanticTypes) { logger.info("\t" + semanticType.getConfidenceScore() + " :" + semanticType.getModelLabelString()); semanticType.getDomain() == null || semanticType.getType() == null) continue; domainUri = semanticType.getDomain().getUri(); propertyUri = semanticType.getType().getUri(); Integer countOfSemanticType = semanticTypesCount.get(domainUri + propertyUri); logger.debug("count of semantic type: " + countOfSemanticType);
public void setType(ArrayList<SemanticType> type) { if(type.size() > 0) { types.put(type.get(0).getHNodeId(), type); } } }
newType = new SemanticType(hNodeId, ClassInstanceLink.getFixedLabel(), classNode.getLabel(), classNode.getId(), newType = new SemanticType(hNodeId, DataPropertyOfColumnLink.getFixedLabel(), classInstanceNode.getLabel(), newType = new SemanticType(hNodeId, ObjectPropertySpecializationLink.getFixedLabel(), classInstanceNode.getLabel(), newType = new SemanticType(hNodeId, ColumnSubClassLink.getFixedLabel(), classNode.getLabel(), classNode.getId(), false, SemanticType.Origin.User, 1.0); if (userSemanticTypes != null) { for (SemanticType st : userSemanticTypes) { if (st.getModelLabelString().equalsIgnoreCase(newType.getModelLabelString())) { duplicateSemanticType = true; break; .getSynonymTypesForHNodeId(newType.getHNodeId());
for (SemanticType st : suggestedTypes) targetLabel += "\n[" + getLocalName(st.getDomain().getUri()) + "," + getLocalName(st.getType().getUri()) + "," + roundDecimals(st.getConfidenceScore(),3) + "]";
private void saveSemanticTypesInformation(Worksheet worksheet, Workspace workspace , Collection<SemanticType> semanticTypes) throws JSONException { JSONArray typesArray = new JSONArray(); // Add the vworksheet information JSONObject vwIDJObj = new JSONObject(); vwIDJObj.put(ClientJsonKeys.name.name(), ParameterType.worksheetId.name()); vwIDJObj.put(ClientJsonKeys.type.name(), ParameterType.worksheetId.name()); vwIDJObj.put(ClientJsonKeys.value.name(), worksheetId); typesArray.put(vwIDJObj); for (SemanticType type: semanticTypes) { // Add the hNode information JSONObject hNodeJObj = new JSONObject(); hNodeJObj.put(ClientJsonKeys.name.name(), ParameterType.hNodeId.name()); hNodeJObj.put(ClientJsonKeys.type.name(), ParameterType.hNodeId.name()); hNodeJObj.put(ClientJsonKeys.value.name(), type.getHNodeId()); typesArray.put(hNodeJObj); // Add the semantic type information JSONObject typeJObj = new JSONObject(); typeJObj.put(ClientJsonKeys.name.name(), ClientJsonKeys.SemanticType.name()); typeJObj.put(ClientJsonKeys.type.name(), ParameterType.other.name()); typeJObj.put(ClientJsonKeys.value.name(), type.getJSONArrayRepresentation()); typesArray.put(typeJObj); } setInputParameterJson(typesArray.toString(4)); }
String hNodeId = newTypes.get(0).getHNodeId(); for (HNodePath path : paths) { if (path.getLeaf().getId().equals(hNodeId)) { ISemanticTypeModelHandler modelHandler = workspace.getSemanticTypeModelHandler(); for(SemanticType newType : newTypes) { String label = newType.getModelLabelString(); modelHandler.addType(label, examples);
if (synonyms != null && !synonyms.getSynonyms().isEmpty()){ for (SemanticType synType:synonyms.getSynonyms()) { if (synType.isClass()) { logger.error("Synonym type as class with no property are not allowed."); continue; Predicate pred = new Predicate(synType.getType().getUri() + "-synonym" + getNewSynonymIdCount()); pred.getTemplate().addTemplateTermToSet( new StringTemplateTerm(synType.getType().getUri(), true)); poMap.setPredicate(pred);
SemanticType newType = new SemanticType(hNodeId, linkLabel, source.getLabel(), source.getId(), isProvenance, SemanticType.Origin.User, 1.0); if (userSemanticTypes != null) { for (SemanticType st : userSemanticTypes) { if (st.getModelLabelString().equalsIgnoreCase(newType.getModelLabelString())) { duplicateSemanticType = true; break;
public List<SemanticType> getSuggestedTypes(OntologyManager ontologyManager, ColumnNode columnNode, SemanticTypeColumnModel columnModel) { ArrayList<SemanticType> suggestedSemanticTypes = new ArrayList<>(); if (columnModel == null) return suggestedSemanticTypes; for (Entry<String, Double> entry : columnModel.getScoreMap().entrySet()) { String key = entry.getKey(); Double confidence = entry.getValue(); if (key == null || key.isEmpty()) continue; String[] parts = key.split("\\|"); if (parts == null || parts.length != 2) continue; String domainUri = parts[0].trim(); String propertyUri = parts[1].trim(); Label domainLabel = ontologyManager.getUriLabel(domainUri); if (domainLabel == null) continue; Label propertyLabel = ontologyManager.getUriLabel(propertyUri); if (propertyLabel == null) continue; SemanticType semanticType = new SemanticType(columnNode.getHNodeId(), propertyLabel, domainLabel, null, false, Origin.TfIdfModel, confidence); logger.info("\t" + propertyUri + " of " + domainUri + ": " + confidence); suggestedSemanticTypes.add(semanticType); } Collections.sort(suggestedSemanticTypes, Collections.reverseOrder()); return suggestedSemanticTypes; }
public JSONObject getJSONArrayRepresentation() throws JSONException { JSONObject typeObj = new JSONObject(); typeObj.put(ClientJsonKeys.FullType.name(), type.getUri()); if(isClass()) typeObj.put(ClientJsonKeys.DomainUri.name(), ""); else typeObj.put(ClientJsonKeys.DomainUri.name(), domain.getUri()); return typeObj; }
public void unassignUserType(SemanticType semanticType) { if (semanticType == null) { if (userSemanticTypes == null || userSemanticTypes.isEmpty()) this.semanticTypeStatus = ColumnSemanticTypeStatus.Unassigned; return; } int tobeDeletedIndex = -1; if (userSemanticTypes != null) { SemanticType st; for (int i = 0; i < userSemanticTypes.size(); i++) { st = userSemanticTypes.get(i); if (st.getModelLabelString().equalsIgnoreCase(semanticType.getModelLabelString())) { tobeDeletedIndex = i; break; } } } if (tobeDeletedIndex != -1 && userSemanticTypes != null) { userSemanticTypes.remove(tobeDeletedIndex); } if (userSemanticTypes == null || userSemanticTypes.isEmpty()) this.semanticTypeStatus = ColumnSemanticTypeStatus.Unassigned; }
private boolean hasType(SemanticType type, String property, String domain) { String typeURI = type.getType().getUri(); String domainURI = type.getDomain().getUri(); if ((typeURI.equals(property) && domainURI.equals(domain)) || (isSubPropertyOf(typeURI, property, true) && isSubClassOf( domainURI, domain, true))) return true; else return false; }
public void addType(SemanticType type) { ArrayList<SemanticType> typeArr = getSemanticTypeForHNodeId(type.getHNodeId()); typeArr.add(type); types.put(type.getHNodeId(), typeArr); }