Last active
August 29, 2015 14:12
-
-
Save policevideorequests/c4ab60f164d9f0fbec43 to your computer and use it in GitHub Desktop.
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 script is free open source code copyright by Timothy A. Clemans 2015 licensed under GPL | |
app.addToolButton({cName: "RedactGoReport", cLabel: "Redact Go Report", cEnable: "event.rc = (app.doc != null);", cExec: "redact(this);" }); | |
var redact = app.trustedFunction( function(doc){ | |
app.beginPriv(); | |
var ssnRgExp = /\d{3}-\d{2}-\d{4}/; // regular expression for finding social security numbers | |
var redactionsMade = []; | |
var allTheWords = ''; // Save all the words so we can search for keywords that indicate whether or not redaction is required and whether or not | |
// there are attachments that need to be manually redacted | |
for (var page=0;page<doc.numPages;page++){ | |
for (var i=0;i<doc.getPageNumWords(page);i++) { | |
allTheWords += doc.getPageNthWord(page,i) + ' '; | |
} | |
} | |
//app.alert(allTheWords); | |
words_to_remove=[]; | |
for(var page=0;page<doc.numPages;page++){ | |
for (var i=0;i<doc.getPageNumWords(page);i++){ | |
// if do not disclose notification | |
if (doc.getPageNthWord(page,i)=='DISCLOSE'){ | |
redactionsMade.push('witness/victim info') | |
words_to_remove.push(doc.getPageNthWord(page,i-6).toLowerCase()); | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i-6),overlayText: "",alignment: 1,repeat:false}); | |
words_to_remove.push(doc.getPageNthWord(page,i-5).toLowerCase()); | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i-5),overlayText: "",alignment: 1,repeat:false}); | |
for (var j=i;j<doc.getPageNumWords(page);j++){ | |
// redact birthday | |
if (doc.getPageNthWord(page,j) == 'birth') { | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,j+1),overlayText: "",alignment: 1,repeat:false}); | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,j+2),overlayText: "",alignment: 1,repeat:false}); | |
} | |
// redact address | |
if (doc.getPageNthWord(page,j) == 'Address') { | |
buildingAddressToRedact = doc.getPageNthWord(page,j+1); | |
var quad=doc.getPageNthWordQuads(page,j+1); | |
quad[0][0]=quad[0][2]-((quad[0][2]-quad[0][0])/doc.getPageNthWord(page,j+1).length)*(doc.getPageNthWord(page,j+1).length-2); | |
quad[0][4]=quad[0][0];doc.addAnnot({type:"Redact",page: page,quads: quad,overlayText: "",alignment: 1,repeat:false}); | |
// remove the address from the narrative | |
for (p=0;p<doc.numPages;p++) { | |
for (w=0;w<doc.getPageNumWords(p);w++) { | |
if (doc.getPageNthWord(p, w) == buildingAddressToRedact) { | |
var quad=doc.getPageNthWordQuads(p,w); | |
quad[0][0]=quad[0][2]-((quad[0][2]-quad[0][0])/doc.getPageNthWord(page,j+1).length)*(doc.getPageNthWord(p,w).length-2); | |
quad[0][4]=quad[0][0];doc.addAnnot({type:"Redact",page: p,quads: quad,overlayText: "",alignment: 1,repeat:false}); | |
} | |
} | |
} | |
} | |
// redact phone number | |
if (doc.getPageNthWord(page,j) == 'Home' || doc.getPageNthWord(page,j) == 'Cellular') { | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,j+1),overlayText: "",alignment: 1,repeat:false}); | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,j+2),overlayText: "",alignment: 1,repeat:false}); | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,j+3),overlayText: "",alignment: 1,repeat:false}); | |
} | |
} | |
} | |
else if (words_to_remove.indexOf(doc.getPageNthWord(page,i).toLowerCase())!=-1){ | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i),overlayText: "",alignment: 1,repeat:false}); | |
} | |
// remove social security numbers | |
else if ((doc.getPageNumWords(page)-i)>3){ | |
var stringToTest =doc.getPageNthWord(page,i, false)+doc.getPageNthWord(page,i+1, false)+doc.getPageNthWord(page,i+2, false); | |
if(ssnRgExp.test(stringToTest)){ | |
redactionsMade.push('social security number') | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i),overlayText: "",alignment: 1,repeat:false}); | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i+1),overlayText: "",alignment: 1,repeat:false}); | |
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i+2),overlayText: "",alignment: 1,repeat:false}); | |
} | |
} | |
} | |
}; | |
var n = allTheWords.search(/Attachment/i); | |
allTheWords; | |
if (n > 0) { | |
if (redactionsMade.length > 0) { | |
app.alert('Following redacted: '+redactionsMade+' There are attachments that need to be manually reviewed/redacted.'); | |
} else { | |
app.alert('There are attachments that need to be manually reviewed/redacted.'); | |
} | |
} else if (redactionsMade.length > 0) { | |
app.alert('Following redacted: '+redactionsMade); | |
} else { | |
app.alert('No incidation that redactions are required.'); | |
} | |
doc.applyRedactions({bKeepMarks: false,bShowConfirmation: false,cProgText: ""}); | |
app.endPriv(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment