Skip to content

Commit 95b0633

Browse files
authored
Populate name fields in nodes (#499)
1 parent fc69175 commit 95b0633

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

pipeline/util/src/main/java/org/datacommons/ingestion/util/GraphReader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static List<Node> graphToNodes(McfGraph graph, Counter mcfNodesWithoutTyp
4343
// Generate corresponding node
4444
Map<String, McfGraph.Values> pv = pvs.getPvsMap();
4545
Node.Builder node = Node.builder();
46-
String dcid = GraphUtils.getPropertyValue(pv, "dcid");
46+
String dcid = GraphUtils.getPropVal(pvs, GraphUtils.Property.dcid.name());
4747
String subjectId = !dcid.isEmpty() ? dcid : McfUtil.stripNamespace(nodeEntry.getKey());
4848
node.subjectId(subjectId);
4949

@@ -54,7 +54,8 @@ public static List<Node> graphToNodes(McfGraph graph, Counter mcfNodesWithoutTyp
5454
mcfNodesWithoutTypeCounter.inc();
5555
}
5656
node.value(subjectId);
57-
node.name(GraphUtils.getPropertyValue(pv, "name"));
57+
String name = GraphUtils.getPropVal(pvs, GraphUtils.Property.name.name());
58+
node.name(!name.isEmpty() ? name : subjectId);
5859
node.types(types);
5960
nodes.add(node.build());
6061

@@ -92,7 +93,7 @@ public static List<Edge> graphToEdges(McfGraph graph, String provenance) {
9293
PropertyValues pvs = nodeEntry.getValue();
9394
if (!GraphUtils.isObservation(pvs)) {
9495
Map<String, McfGraph.Values> pv = pvs.getPvsMap();
95-
String dcid = GraphUtils.getPropertyValue(pv, "dcid");
96+
String dcid = GraphUtils.getPropVal(pvs, GraphUtils.Property.dcid.name());
9697
String subjectId = !dcid.isEmpty() ? dcid : McfUtil.stripNamespace(nodeEntry.getKey());
9798
for (Map.Entry<String, McfGraph.Values> entry : pv.entrySet()) {
9899
if (entry.getKey().equals("dcid")) {

pipeline/util/src/test/java/org/datacommons/ingestion/util/GraphReaderTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ public void testGraphToNodes() {
117117
.name("Node One")
118118
.types(List.of("Property"))
119119
.build(),
120-
Node.builder().subjectId("dcid2").value("dcid2").types(List.of("Thing")).build(),
120+
Node.builder()
121+
.subjectId("dcid2")
122+
.value("dcid2")
123+
.name("dcid2")
124+
.types(List.of("Thing"))
125+
.build(),
121126
Node.builder()
122127
.subjectId("Node Zero:kUyRupzrJkxe/HIOIctxlJX4woEGeOTtlVwqyXYnfDE=")
123128
.value("Node Zero")

util/src/main/java/org/datacommons/util/GraphUtils.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public enum Property {
3232
measurementMethod,
3333
unit,
3434
value,
35+
name,
3536
scalingFactor,
3637
dcid;
3738
}
@@ -98,8 +99,7 @@ public static boolean useDcidForLocalNodeIdInOptimizedMcf(String dcid, String lo
9899
* @return True if the property values indicate a StatVarObservation, false otherwise.
99100
*/
100101
public static boolean isObservation(PropertyValues pvs) {
101-
return GraphUtils.getPropertyValue(pvs.getPvsMap(), GraphUtils.Property.typeOf.name())
102-
.contains(GraphUtils.STAT_VAR_OB);
102+
return getPropVal(pvs, GraphUtils.Property.typeOf.name()).contains(GraphUtils.STAT_VAR_OB);
103103
}
104104

105105
/**
@@ -129,11 +129,7 @@ public static String getPropVal(McfGraph.PropertyValues node, String prop) {
129129
McfGraph.Values v = node.getPvsMap().get(prop);
130130
if (v != null && v.getTypedValuesCount() > 0) {
131131
String val = v.getTypedValues(0).getValue();
132-
if (val.startsWith("dcid:") || val.startsWith("dcs:") || val.startsWith("schema:")) {
133-
return val.substring(val.indexOf(':') + 1);
134-
} else {
135-
return val;
136-
}
132+
return McfUtil.stripNamespace(val);
137133
}
138134
return "";
139135
}

0 commit comments

Comments
 (0)