Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ public void process(ProcessContext c) {
if (!g.getNodesMap().isEmpty()) {
// Access the single element in the map.
PropertyValues pvs = g.getNodesMap().entrySet().iterator().next().getValue();
if (GraphUtils.isStatisticalPopulation(pvs)) {
return;
}
if (GraphUtils.isObservation(pvs)) {
c.output(OBSERVATION_NODES_TAG, g);
} else {
Expand Down
16 changes: 16 additions & 0 deletions util/src/main/java/org/datacommons/util/GraphUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ public static boolean isObservation(PropertyValues pvs) {
return getPropVal(pvs, GraphUtils.Property.typeOf.name()).contains(GraphUtils.STAT_VAR_OB);
}

/**
* Checks if a given set of property values represents a StatisticalPopulation node.
*
* @param pvs The property values to check.
* @return True if the property values indicate a StatisticalPopulation, false otherwise.
*/
public static boolean isStatisticalPopulation(PropertyValues pvs) {
List<String> types = getPropertyValues(pvs.getPvsMap(), Property.typeOf.name());
for (String type : types) {
if (McfUtil.stripNamespace(type).equals(Vocabulary.STATISTICAL_POPULATION_TYPE)) {
return true;
}
}
return false;
}
Comment on lines +116 to +124

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The helper method getPropertyValues already strips namespaces from the returned values (using McfUtil.stripNamespace). Therefore, calling McfUtil.stripNamespace(type) again inside the loop is redundant. We can simplify this method by directly checking if the returned list contains Vocabulary.STATISTICAL_POPULATION_TYPE.

  public static boolean isStatisticalPopulation(PropertyValues pvs) {
    return getPropertyValues(pvs.getPvsMap(), Property.typeOf.name())
        .contains(Vocabulary.STATISTICAL_POPULATION_TYPE);
  }


/**
* Updates a PV in an McfGraph instance
*
Expand Down
1 change: 1 addition & 0 deletions util/src/main/java/org/datacommons/util/Vocabulary.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class Vocabulary {
public static final String SOURCE_TYPE = "Source";
public static final String STAT_VAR_TYPE = "StatisticalVariable";
public static final String STAT_VAR_OBSERVATION_TYPE = "StatVarObservation";
public static final String STATISTICAL_POPULATION_TYPE = "StatisticalPopulation";
public static final String LEGACY_OBSERVATION_TYPE_SUFFIX = "Observation";
public static final String LEGACY_POPULATION_TYPE_SUFFIX = "Population";
public static final String STAT_VAR_GROUP_TYPE = "StatVarGroup";
Expand Down