-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Duplicate node id validation improved, class renamed. Stats command n…
…ow returns counts sorted in decreasing order.
- Loading branch information
1 parent
b66d06c
commit c0f0380
Showing
13 changed files
with
201 additions
and
217 deletions.
There are no files selected for viewing
101 changes: 51 additions & 50 deletions
101
DataTagsLib/WORK/policy-models/dg-large-modular/questionnaire.dg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,68 @@ | ||
<* | ||
DISCLAIMER: | ||
NOT TO BE USED AS A LEGAL ADVICE | ||
DISCLAIMER: | ||
NOT TO BE USED AS A LEGAL ADVICE | ||
*> | ||
[#import ppra: ppra.dg ] | ||
[#import medical: medical.dg ] | ||
[#import ferpa: ferpa.dg ] | ||
[#import dppa: dppa.dg ] | ||
[#import gov: government-records.dg ] | ||
[>global-start< ask: | ||
{text: Do the data concern living persons?} | ||
{text: Do the data concern living persons?} | ||
{answers: | ||
{yes: | ||
[set: Code=green] <-- Explicit settings of colors is going away soon! | ||
[>filter-medical< ask: | ||
{text: Do the data contain health or medical information?} | ||
{answers: | ||
{yes: [call: medical>start]}} | ||
] | ||
[>filter-ppra< ask: | ||
{text: Was the data collected from students in an elementary or secondary school?} | ||
{answers: | ||
{yes: [call: ppra>start]} | ||
} | ||
] | ||
[>filter-ferpa< ask: | ||
{text: Do the data contain any information derived from ministry of education data?} | ||
{answers: | ||
{yes: [call: ferpa>start]} | ||
}] | ||
[call: gov>Gov1] | ||
[call: dppa>DPPA1] | ||
[>futures< todo: Future additions go here.]} | ||
[>filter-medical< ask: | ||
{text: Do the data contain health or medical information?} | ||
{answers: | ||
{yes: [call: medical>start]}} | ||
] | ||
[>filter-ppra< ask: | ||
{text: Was the data collected from students in an elementary or secondary school?} | ||
{answers: | ||
{yes: [call: ppra>start]} | ||
} | ||
] | ||
[>filter-ferpa< ask: | ||
{text: Do the data contain any information derived from ministry of education data?} | ||
{answers: | ||
{yes: [call: ferpa>start]} | ||
}] | ||
[call: gov>Gov1] | ||
[call: dppa>DPPA1] | ||
[>futures< todo: Future additions go here.]} | ||
{no: [set: Code=blue; Identity=noPersonData] } | ||
}] | ||
[call: dua] | ||
[end] | ||
}] | ||
[call: dua] | ||
[end] | ||
|
||
[>dua< section: | ||
{title: Data Use Agreements} | ||
[>dua-ext< todo: Data use agreements] | ||
[>duaTimeLimit< ask: | ||
{text: Is there any reason why we cannot store the data indefinitely? } | ||
{answers: | ||
{no: [set: TimeLimit=none] } | ||
{yes: | ||
[ask: | ||
{text:For how long should we keep the data?} | ||
{answers: | ||
{ indefinitely: [set: TimeLimit=none] } | ||
{ 50 years: [set: TimeLimit=_50yr] } | ||
{ 5 years: [set: TimeLimit=_5yr] } | ||
{ 2 years: [set: TimeLimit=_2yr] } | ||
{ 1 year: [set: TimeLimit=_1yr] } | ||
}]}}] | ||
[>duaAdditional< ask: | ||
{text: Did the data have any restrictions on sharing, e.g. stated in an agreement or policy statement?} | ||
{answers: | ||
{yes: [set: ContractOrPolicy=yes]} | ||
{no: [set: ContractOrPolicy=no]}} | ||
] | ||
[>dua< section: | ||
{title: Data Use Agreements} | ||
[>dua-ext< todo: Data use agreements] | ||
[>duaTimeLimit< ask: | ||
{text: Is there any reason why we cannot store the data indefinitely? } | ||
{answers: | ||
{no: [set: TimeLimit=none] } | ||
{yes: | ||
[ask: | ||
{text:For how long should we keep the data?} | ||
{answers: | ||
{ indefinitely: [set: TimeLimit=none] } | ||
{ 50 years: [set: TimeLimit=_50yr] } | ||
{ 5 years: [set: TimeLimit=_5yr] } | ||
{ 2 years: [set: TimeLimit=_2yr] } | ||
{ 1 year: [set: TimeLimit=_1yr] } | ||
}]}}] | ||
[>duaAdditional< ask: | ||
{text: Did the data have any restrictions on sharing, e.g. stated in an agreement or policy statement?} | ||
{answers: | ||
{yes: [set: ContractOrPolicy=yes]} | ||
{no: [set: ContractOrPolicy=no]} | ||
} | ||
] | ||
] | ||
[end] | ||
<* | ||
DISCLAIMER: | ||
NOT TO BE USED AS A LEGAL ADVICE | ||
DISCLAIMER: | ||
NOT TO BE USED AS A LEGAL ADVICE | ||
*> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
application.args=policy-models/dg-large-modular | ||
application.args=policy-models/import | ||
work.dir=WORK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
DataTagsLib/src/edu/harvard/iq/datatags/tools/DuplicateIdValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package edu.harvard.iq.datatags.tools; | ||
|
||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstAnswerSubNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstAskNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstCallNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstConsiderAnswerSubNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstConsiderNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstEndNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstNode.NullVisitor; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstRejectNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstSectionNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstSetNode; | ||
import edu.harvard.iq.datatags.parser.decisiongraph.ast.AstTodoNode; | ||
import edu.harvard.iq.datatags.runtime.exceptions.DataTagsRuntimeException; | ||
import edu.harvard.iq.datatags.tools.ValidationMessage.Level; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
/** | ||
* Checks that every id in the questionnaire is unique. Returns an ERROR with | ||
* each repeated node id. | ||
* | ||
* @author Naomi | ||
* @author Michael | ||
*/ | ||
public class DuplicateIdValidator extends NullVisitor implements DecisionGraphAstValidator { | ||
|
||
private final Map<String, List<AstNode>> nodesById = new HashMap<>(); | ||
|
||
@Override | ||
public List<ValidationMessage> validate(List<? extends AstNode> refs) { | ||
nodesById.clear(); | ||
|
||
refs.stream().forEach(ref -> ref.accept(this)); | ||
|
||
return nodesById.entrySet().stream().filter( ent -> ent.getValue().size()>1 ) | ||
.map( ent -> new ValidationMessage(Level.ERROR, | ||
String.format("Duplicate node id: '%s' (nodes: %s)", ent.getKey(), ent.getValue())) ) | ||
.collect( toList() ); | ||
|
||
} | ||
|
||
@Override | ||
public void visitImpl(AstConsiderNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
for (AstConsiderAnswerSubNode ansRef : nd.getAnswers()) { | ||
for (AstNode node : ansRef.getSubGraph()) { | ||
node.accept(this); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void visitImpl(AstAskNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
for (AstAnswerSubNode ansRef : nd.getAnswers()) { | ||
for (AstNode node : ansRef.getSubGraph()) { | ||
node.accept(this); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void visitImpl(AstSetNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
} | ||
|
||
@Override | ||
public void visitImpl(AstRejectNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
} | ||
|
||
@Override | ||
public void visitImpl(AstCallNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
} | ||
|
||
@Override | ||
public void visitImpl(AstTodoNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
} | ||
|
||
@Override | ||
public void visitImpl(AstEndNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
} | ||
|
||
@Override | ||
public void visitImpl(AstSectionNode nd) throws DataTagsRuntimeException { | ||
collect(nd); | ||
} | ||
|
||
private void collect( AstNode nd ) { | ||
nodesById.computeIfAbsent(nd.getId(), str -> new ArrayList<>(1)).add(nd); | ||
} | ||
|
||
} |
Oops, something went wrong.