code
stringlengths
67
466k
docstring
stringlengths
1
13.2k
@Override final protected void addSinglePoint(int position, int additionalId, long additionalRef, Integer id, Long ref) { addRange(position, position, additionalId, additionalRef, id, ref); }
/* (non-Javadoc) @see mtas.codec.tree.MtasTree#addSinglePoint(int, java.lang.Integer, java.lang.Long)
@Override final protected void addRange(int left, int right, int additionalId, long additionalRef, Integer id, Long ref) { String key = left + "_" + right; if (index.containsKey(key)) { index.get(key).addIdAndRef(id, ref, additionalId, additionalRef); } else { root = addRange(root, left, right, additionalId, additionalRef, id, ref); root.color = MtasRBTreeNode.BLACK; } }
/* (non-Javadoc) @see mtas.codec.tree.MtasTree#addRange(int, int, java.lang.Integer, java.lang.Long)
private MtasRBTreeNode addRange(MtasRBTreeNode n, Integer left, Integer right, int additionalId, long additionalRef, Integer id, Long ref) { MtasRBTreeNode localN = n; if (localN == null) { String key = left.toString() + "_" + right.toString(); localN = new MtasRBTreeNode(left, right, MtasRBTreeNode.RED, 1); localN.addIdAndRef(id, ref, additionalId, additionalRef); index.put(key, localN); } else { if (left <= localN.left) { localN.leftChild = addRange(localN.leftChild, left, right, additionalId, additionalRef, id, ref); updateMax(localN, localN.leftChild); } else { localN.rightChild = addRange(localN.rightChild, left, right, additionalId, additionalRef, id, ref); updateMax(localN, localN.rightChild); } if (isRed(localN.rightChild) && !isRed(localN.leftChild)) { localN = rotateLeft(localN); } if (isRed(localN.leftChild) && isRed(localN.leftChild.leftChild)) { localN = rotateRight(localN); } if (isRed(localN.leftChild) && isRed(localN.rightChild)) { flipColors(localN); } localN.n = size(localN.leftChild) + size(localN.rightChild) + 1; } return localN; }
Adds the range. @param n the n @param left the left @param right the right @param additionalId the additional id @param additionalRef the additional ref @param id the id @param ref the ref @return the mtas RB tree node
private void updateMax(MtasRBTreeNode n, MtasRBTreeNode c) { if (c != null) { if (n.max < c.max) { n.max = c.max; } } }
Update max. @param n the n @param c the c
private MtasRBTreeNode rotateRight(MtasRBTreeNode n) { assert (n != null) && isRed(n.leftChild); MtasRBTreeNode x = n.leftChild; n.leftChild = x.rightChild; x.rightChild = n; x.color = x.rightChild.color; x.rightChild.color = MtasRBTreeNode.RED; x.n = n.n; n.n = size(n.leftChild) + size(n.rightChild) + 1; setMax(n); setMax(x); return x; }
Rotate right. @param n the n @return the mtas RB tree node
private void flipColors(MtasRBTreeNode n) { // n must have opposite color of its two children assert (n != null) && (n.leftChild != null) && (n.rightChild != null); assert (!isRed(n) && isRed(n.leftChild) && isRed(n.rightChild)) || (isRed(n) && !isRed(n.leftChild) && !isRed(n.rightChild)); n.color ^= 1; n.leftChild.color ^= 1; n.rightChild.color ^= 1; }
Flip colors. @param n the n
private boolean isRed(MtasRBTreeNode n) { if (n == null) { return false; } return n.color == MtasRBTreeNode.RED; }
Checks if is red. @param n the n @return true, if is red
private void setMax(MtasRBTreeNode n) { n.max = n.right; if (n.leftChild != null) { n.max = Math.max(n.max, n.leftChild.max); } if (n.rightChild != null) { n.max = Math.max(n.max, n.rightChild.max); } }
Sets the max. @param n the new max
public static base_response update(nitro_service client, filterhtmlinjectionparameter resource) throws Exception { filterhtmlinjectionparameter updateresource = new filterhtmlinjectionparameter(); updateresource.rate = resource.rate; updateresource.frequency = resource.frequency; updateresource.strict = resource.strict; updateresource.htmlsearchlen = resource.htmlsearchlen; return updateresource.update_resource(client); }
Use this API to update filterhtmlinjectionparameter.
public static base_response unset(nitro_service client, filterhtmlinjectionparameter resource, String[] args) throws Exception{ filterhtmlinjectionparameter unsetresource = new filterhtmlinjectionparameter(); return unsetresource.unset_resource(client,args); }
Use this API to unset the properties of filterhtmlinjectionparameter resource. Properties that need to be unset are specified in args array.
public static filterhtmlinjectionparameter get(nitro_service service, options option) throws Exception{ filterhtmlinjectionparameter obj = new filterhtmlinjectionparameter(); filterhtmlinjectionparameter[] response = (filterhtmlinjectionparameter[])obj.get_resources(service,option); return response[0]; }
Use this API to fetch all the filterhtmlinjectionparameter resources that are configured on netscaler.
public static aaauser_binding get(nitro_service service, String username) throws Exception{ aaauser_binding obj = new aaauser_binding(); obj.set_username(username); aaauser_binding response = (aaauser_binding) obj.get_resource(service); return response; }
Use this API to fetch aaauser_binding resource of given name .
public static sslvserver_sslcertkey_binding[] get(nitro_service service, String vservername) throws Exception{ sslvserver_sslcertkey_binding obj = new sslvserver_sslcertkey_binding(); obj.set_vservername(vservername); sslvserver_sslcertkey_binding response[] = (sslvserver_sslcertkey_binding[]) obj.get_resources(service); return response; }
Use this API to fetch sslvserver_sslcertkey_binding resources of given name .
public Label newLabel(String labelStr, int options) { if (options == TAG_LABEL) { return new TaggedWord(null, labelStr); } return new TaggedWord(labelStr); }
Make a new label with this <code>String</code> as a value component. Any other fields of the label would normally be null. @param labelStr The String that will be used for value @param options what to make (use labelStr as word or tag) @return The new TaggedWord (tag or word will be <code>null</code>)
public static base_response unset(nitro_service client, tmsessionparameter resource, String[] args) throws Exception{ tmsessionparameter unsetresource = new tmsessionparameter(); return unsetresource.unset_resource(client,args); }
Use this API to unset the properties of tmsessionparameter resource. Properties that need to be unset are specified in args array.
public static tmsessionparameter get(nitro_service service) throws Exception{ tmsessionparameter obj = new tmsessionparameter(); tmsessionparameter[] response = (tmsessionparameter[])obj.get_resources(service); return response[0]; }
Use this API to fetch all the tmsessionparameter resources that are configured on netscaler.
public static base_response add(nitro_service client, systemuser resource) throws Exception { systemuser addresource = new systemuser(); addresource.username = resource.username; addresource.password = resource.password; addresource.externalauth = resource.externalauth; addresource.promptstring = resource.promptstring; addresource.timeout = resource.timeout; return addresource.add_resource(client); }
Use this API to add systemuser.
public static base_responses add(nitro_service client, systemuser resources[]) throws Exception { base_responses result = null; if (resources != null && resources.length > 0) { systemuser addresources[] = new systemuser[resources.length]; for (int i=0;i<resources.length;i++){ addresources[i] = new systemuser(); addresources[i].username = resources[i].username; addresources[i].password = resources[i].password; addresources[i].externalauth = resources[i].externalauth; addresources[i].promptstring = resources[i].promptstring; addresources[i].timeout = resources[i].timeout; } result = add_bulk_request(client, addresources); } return result; }
Use this API to add systemuser resources.
public static base_response delete(nitro_service client, String username) throws Exception { systemuser deleteresource = new systemuser(); deleteresource.username = username; return deleteresource.delete_resource(client); }
Use this API to delete systemuser of given name.
public static base_response update(nitro_service client, systemuser resource) throws Exception { systemuser updateresource = new systemuser(); updateresource.username = resource.username; updateresource.password = resource.password; updateresource.externalauth = resource.externalauth; updateresource.promptstring = resource.promptstring; updateresource.timeout = resource.timeout; return updateresource.update_resource(client); }
Use this API to update systemuser.
public static base_responses update(nitro_service client, systemuser resources[]) throws Exception { base_responses result = null; if (resources != null && resources.length > 0) { systemuser updateresources[] = new systemuser[resources.length]; for (int i=0;i<resources.length;i++){ updateresources[i] = new systemuser(); updateresources[i].username = resources[i].username; updateresources[i].password = resources[i].password; updateresources[i].externalauth = resources[i].externalauth; updateresources[i].promptstring = resources[i].promptstring; updateresources[i].timeout = resources[i].timeout; } result = update_bulk_request(client, updateresources); } return result; }
Use this API to update systemuser resources.
public static base_response unset(nitro_service client, systemuser resource, String[] args) throws Exception{ systemuser unsetresource = new systemuser(); unsetresource.username = resource.username; return unsetresource.unset_resource(client,args); }
Use this API to unset the properties of systemuser resource. Properties that need to be unset are specified in args array.
public static base_responses unset(nitro_service client, String username[], String args[]) throws Exception { base_responses result = null; if (username != null && username.length > 0) { systemuser unsetresources[] = new systemuser[username.length]; for (int i=0;i<username.length;i++){ unsetresources[i] = new systemuser(); unsetresources[i].username = username[i]; } result = unset_bulk_request(client, unsetresources,args); } return result; }
Use this API to unset the properties of systemuser resources. Properties that need to be unset are specified in args array.
public static systemuser[] get(nitro_service service) throws Exception{ systemuser obj = new systemuser(); systemuser[] response = (systemuser[])obj.get_resources(service); return response; }
Use this API to fetch all the systemuser resources that are configured on netscaler.
public static systemuser get(nitro_service service, String username) throws Exception{ systemuser obj = new systemuser(); obj.set_username(username); systemuser response = (systemuser) obj.get_resource(service); return response; }
Use this API to fetch systemuser resource of given name .
public static systemuser[] get_filtered(nitro_service service, String filter) throws Exception{ systemuser obj = new systemuser(); options option = new options(); option.set_filter(filter); systemuser[] response = (systemuser[]) obj.getfiltered(service, option); return response; }
Use this API to fetch filtered set of systemuser resources. filter string should be in JSON format.eg: "port:80,servicetype:HTTP".
public static service_stats[] get(nitro_service service) throws Exception{ service_stats obj = new service_stats(); service_stats[] response = (service_stats[])obj.stat_resources(service); return response; }
Use this API to fetch the statistics of all service_stats resources that are configured on netscaler.
public static service_stats get(nitro_service service, String name) throws Exception{ service_stats obj = new service_stats(); obj.set_name(name); service_stats response = (service_stats) obj.stat_resource(service); return response; }
Use this API to fetch statistics of service_stats resource of given name .
public static base_response update(nitro_service client, inatparam resource) throws Exception { inatparam updateresource = new inatparam(); updateresource.nat46v6prefix = resource.nat46v6prefix; updateresource.nat46ignoretos = resource.nat46ignoretos; updateresource.nat46zerochecksum = resource.nat46zerochecksum; updateresource.nat46v6mtu = resource.nat46v6mtu; updateresource.nat46fragheader = resource.nat46fragheader; return updateresource.update_resource(client); }
Use this API to update inatparam.
public static base_response unset(nitro_service client, inatparam resource, String[] args) throws Exception{ inatparam unsetresource = new inatparam(); return unsetresource.unset_resource(client,args); }
Use this API to unset the properties of inatparam resource. Properties that need to be unset are specified in args array.
public static inatparam get(nitro_service service) throws Exception{ inatparam obj = new inatparam(); inatparam[] response = (inatparam[])obj.get_resources(service); return response[0]; }
Use this API to fetch all the inatparam resources that are configured on netscaler.
@Override public MtasSpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { if (q1 == null || q2 == null) { return null; } else { MtasSpanIntersectingQueryWeight w1 = new MtasSpanIntersectingQueryWeight( q1.createWeight(searcher, needsScores, boost)); MtasSpanIntersectingQueryWeight w2 = new MtasSpanIntersectingQueryWeight( q2.createWeight(searcher, needsScores, boost)); // subWeights List<MtasSpanIntersectingQueryWeight> subWeights = new ArrayList<>(); subWeights.add(w1); subWeights.add(w2); // return return new SpanIntersectingWeight(w1, w2, searcher, needsScores ? getTermContexts(subWeights) : null, boost); } }
/* (non-Javadoc) @see org.apache.lucene.search.spans.SpanQuery#createWeight(org.apache.lucene. search.IndexSearcher, boolean)
@Override public MtasSpanQuery rewrite(IndexReader reader) throws IOException { MtasSpanQuery newQ1 = (MtasSpanQuery) q1.rewrite(reader); MtasSpanQuery newQ2 = (MtasSpanQuery) q2.rewrite(reader); if (!newQ1.equals(q1) || !newQ2.equals(q2)) { return new MtasSpanIntersectingQuery(newQ1, newQ2).rewrite(reader); } else if (newQ1.equals(newQ2)) { return newQ1; } else { boolean returnNone; returnNone = newQ1.getMaximumWidth() != null && newQ1.getMaximumWidth() == 0; returnNone |= newQ2.getMaximumWidth() != null && newQ2.getMaximumWidth() == 0; if (returnNone) { return new MtasSpanMatchNoneQuery(this.getField()); } else { return super.rewrite(reader); } } }
/* (non-Javadoc) @see mtas.search.spans.util.MtasSpanQuery#rewrite(org.apache.lucene.index. IndexReader)
public float conditionalLogProb(int[] given, int of) { if (given.length != windowSize - 1) { System.err.println("error computing conditional log prob"); System.exit(0); } int[] label = indicesFront(given); float[] masses = new float[label.length]; for (int i = 0; i < masses.length; i++) { masses[i] = table[label[i]]; } float z = ArrayMath.logSum(masses); return table[indexOf(given, of)] - z; }
given is at the begining, of is at the end
public static base_response update(nitro_service client, aaaparameter resource) throws Exception { aaaparameter updateresource = new aaaparameter(); updateresource.enablestaticpagecaching = resource.enablestaticpagecaching; updateresource.enableenhancedauthfeedback = resource.enableenhancedauthfeedback; updateresource.defaultauthtype = resource.defaultauthtype; updateresource.maxaaausers = resource.maxaaausers; updateresource.maxloginattempts = resource.maxloginattempts; updateresource.failedlogintimeout = resource.failedlogintimeout; updateresource.aaadnatip = resource.aaadnatip; return updateresource.update_resource(client); }
Use this API to update aaaparameter.
public static base_response unset(nitro_service client, aaaparameter resource, String[] args) throws Exception{ aaaparameter unsetresource = new aaaparameter(); return unsetresource.unset_resource(client,args); }
Use this API to unset the properties of aaaparameter resource. Properties that need to be unset are specified in args array.
public static aaaparameter get(nitro_service service) throws Exception{ aaaparameter obj = new aaaparameter(); aaaparameter[] response = (aaaparameter[])obj.get_resources(service); return response[0]; }
Use this API to fetch all the aaaparameter resources that are configured on netscaler.
public static gslbvserver_spilloverpolicy_binding[] get(nitro_service service, String name) throws Exception{ gslbvserver_spilloverpolicy_binding obj = new gslbvserver_spilloverpolicy_binding(); obj.set_name(name); gslbvserver_spilloverpolicy_binding response[] = (gslbvserver_spilloverpolicy_binding[]) obj.get_resources(service); return response; }
Use this API to fetch gslbvserver_spilloverpolicy_binding resources of given name .
public void setFirstOccurence(int min, int max) throws ParseException { if (fullCondition == null) { if ((min < 0) || (min > max) || (max < 1)) { throw new ParseException("Illegal number {" + min + "," + max + "}"); } if (min == 0) { firstOptional = true; } firstMinimumOccurence = Math.max(1, min); firstMaximumOccurence = max; } else { throw new ParseException("fullCondition already generated"); } }
Sets the first occurence. @param min the min @param max the max @throws ParseException the parse exception
public MtasCQLParserSentenceCondition createFullSentence() throws ParseException { if (fullCondition == null) { if (secondSentencePart == null) { if (firstBasicSentence != null) { fullCondition = new MtasCQLParserSentenceCondition(firstBasicSentence, ignoreClause, maximumIgnoreLength); } else { fullCondition = firstSentence; } fullCondition.setOccurence(firstMinimumOccurence, firstMaximumOccurence); if (firstOptional) { fullCondition.setOptional(firstOptional); } return fullCondition; } else { if (!orOperator) { if (firstBasicSentence != null) { firstBasicSentence.setOccurence(firstMinimumOccurence, firstMaximumOccurence); firstBasicSentence.setOptional(firstOptional); fullCondition = new MtasCQLParserSentenceCondition( firstBasicSentence, ignoreClause, maximumIgnoreLength); } else { firstSentence.setOccurence(firstMinimumOccurence, firstMaximumOccurence); firstSentence.setOptional(firstOptional); fullCondition = new MtasCQLParserSentenceCondition(firstSentence, ignoreClause, maximumIgnoreLength); } fullCondition.addSentenceToEndLatestSequence( secondSentencePart.createFullSentence()); } else { MtasCQLParserSentenceCondition sentence = secondSentencePart .createFullSentence(); if (firstBasicSentence != null) { sentence.addSentenceAsFirstOption( new MtasCQLParserSentenceCondition(firstBasicSentence, ignoreClause, maximumIgnoreLength)); } else { sentence.addSentenceAsFirstOption(firstSentence); } fullCondition = sentence; } return fullCondition; } } else { return fullCondition; } }
Creates the full sentence. @return the mtas CQL parser sentence condition @throws ParseException the parse exception
public static base_response update(nitro_service client, vserver resource) throws Exception { vserver updateresource = new vserver(); updateresource.name = resource.name; updateresource.backupvserver = resource.backupvserver; updateresource.redirecturl = resource.redirecturl; updateresource.cacheable = resource.cacheable; updateresource.clttimeout = resource.clttimeout; updateresource.somethod = resource.somethod; updateresource.sopersistence = resource.sopersistence; updateresource.sopersistencetimeout = resource.sopersistencetimeout; updateresource.sothreshold = resource.sothreshold; updateresource.pushvserver = resource.pushvserver; return updateresource.update_resource(client); }
Use this API to update vserver.
public static base_response disable(nitro_service client, String name) throws Exception { vserver disableresource = new vserver(); disableresource.name = name; return disableresource.perform_operation(client,"disable"); }
Use this API to disable vserver of given name.
protected static double[] smooth(List<double[]> toSmooth){ double[] smoothed = new double[toSmooth.get(0).length]; for(double[] thisArray:toSmooth){ ArrayMath.pairwiseAddInPlace(smoothed,thisArray); } ArrayMath.multiplyInPlace(smoothed,1/((double) toSmooth.size() )); return smoothed; }
/* This is used to smooth the gradients, providing a more robust calculation which generally leads to a better routine.
public static base_response update(nitro_service client, systemcollectionparam resource) throws Exception { systemcollectionparam updateresource = new systemcollectionparam(); updateresource.communityname = resource.communityname; updateresource.loglevel = resource.loglevel; updateresource.datapath = resource.datapath; return updateresource.update_resource(client); }
Use this API to update systemcollectionparam.
public static base_response unset(nitro_service client, systemcollectionparam resource, String[] args) throws Exception{ systemcollectionparam unsetresource = new systemcollectionparam(); return unsetresource.unset_resource(client,args); }
Use this API to unset the properties of systemcollectionparam resource. Properties that need to be unset are specified in args array.
public static systemcollectionparam get(nitro_service service) throws Exception{ systemcollectionparam obj = new systemcollectionparam(); systemcollectionparam[] response = (systemcollectionparam[])obj.get_resources(service); return response[0]; }
Use this API to fetch all the systemcollectionparam resources that are configured on netscaler.
public static base_response sync(nitro_service client, gslbconfig resource) throws Exception { gslbconfig syncresource = new gslbconfig(); syncresource.preview = resource.preview; syncresource.debug = resource.debug; syncresource.forcesync = resource.forcesync; syncresource.nowarn = resource.nowarn; syncresource.saveconfig = resource.saveconfig; syncresource.command = resource.command; return syncresource.perform_operation(client,"sync"); }
Use this API to sync gslbconfig.
public static int lookupShaper(String name) { if (name == null) { return NOWORDSHAPE; } else if (name.equalsIgnoreCase("dan1")) { return WORDSHAPEDAN1; } else if (name.equalsIgnoreCase("chris1")) { return WORDSHAPECHRIS1; } else if (name.equalsIgnoreCase("dan2")) { return WORDSHAPEDAN2; } else if (name.equalsIgnoreCase("dan2useLC")) { return WORDSHAPEDAN2USELC; } else if (name.equalsIgnoreCase("dan2bio")) { return WORDSHAPEDAN2BIO; } else if (name.equalsIgnoreCase("dan2bioUseLC")) { return WORDSHAPEDAN2BIOUSELC; } else if (name.equalsIgnoreCase("jenny1")) { return WORDSHAPEJENNY1; } else if (name.equalsIgnoreCase("jenny1useLC")) { return WORDSHAPEJENNY1USELC; } else if (name.equalsIgnoreCase("chris2")) { return WORDSHAPECHRIS2; } else if (name.equalsIgnoreCase("chris2useLC")) { return WORDSHAPECHRIS2USELC; } else if (name.equalsIgnoreCase("chris3")) { return WORDSHAPECHRIS3; } else if (name.equalsIgnoreCase("chris3useLC")) { return WORDSHAPECHRIS3USELC; } else if (name.equalsIgnoreCase("chris4")) { return WORDSHAPECHRIS4; } else if (name.equalsIgnoreCase("digits")) { return WORDSHAPEDIGITS; } else { return NOWORDSHAPE; } }
Look up a shaper by a short String name. @param name Shaper name. Known names have patterns along the lines of: dan[12](bio)?(UseLC)?, jenny1(useLC)?, chris[1234](useLC)?. @return An integer constant for the shaper
private static boolean dontUseLC(int shape) { return shape == WORDSHAPEDAN2 || shape == WORDSHAPEDAN2BIO || shape == WORDSHAPEJENNY1 || shape == WORDSHAPECHRIS2 || shape == WORDSHAPECHRIS3; }
Returns true if the specified word shaper doesn't use known lower case words, even if a list of them is present. This is used for backwards compatibility. It is suggested that new word shape functions are either passed a non-null list of lowercase words or not, depending on whether you want knownLC marking (if it is available in a shaper). This is how chris4 works. @param shape One of the defined shape constants @return true if the specified word shaper uses known lower case words.
public static String wordShape(String inStr, int wordShaper, Collection<String> knownLCWords) { // this first bit is for backwards compatibility with how things were first // implemented, where the word shaper name encodes whether to useLC. // If the shaper is in the old compatibility list, then a specified // list of knownLCwords is ignored if (knownLCWords != null && dontUseLC(wordShaper)) { knownLCWords = null; } switch (wordShaper) { case NOWORDSHAPE: return inStr; case WORDSHAPEDAN1: return wordShapeDan1(inStr); case WORDSHAPECHRIS1: return wordShapeChris1(inStr); case WORDSHAPEDAN2: return wordShapeDan2(inStr, knownLCWords); case WORDSHAPEDAN2USELC: return wordShapeDan2(inStr, knownLCWords); case WORDSHAPEDAN2BIO: return wordShapeDan2Bio(inStr, knownLCWords); case WORDSHAPEDAN2BIOUSELC: return wordShapeDan2Bio(inStr, knownLCWords); case WORDSHAPEJENNY1: return wordShapeJenny1(inStr, knownLCWords); case WORDSHAPEJENNY1USELC: return wordShapeJenny1(inStr, knownLCWords); case WORDSHAPECHRIS2: return wordShapeChris2(inStr, false, knownLCWords); case WORDSHAPECHRIS2USELC: return wordShapeChris2(inStr, false, knownLCWords); case WORDSHAPECHRIS3: return wordShapeChris2(inStr, true, knownLCWords); case WORDSHAPECHRIS3USELC: return wordShapeChris2(inStr, true, knownLCWords); case WORDSHAPECHRIS4: return wordShapeChris4(inStr, false, knownLCWords); case WORDSHAPEDIGITS: return wordShapeDigits(inStr); default: throw new IllegalStateException("Bad WordShapeClassifier"); } }
Specify the string and the int identifying which word shaper to use and this returns the result of using that wordshaper on the String. @param inStr String to calculate word shape of @param wordShaper Constant for which shaping formula to use @param knownLCWords A Collection of known lowercase words, which some shapers use to decide the class of capitalized words. <i>Note: while this code works with any Collection, you should provide a Set for decent performance.</i> If this parameter is null or empty, then this option is not used (capitalized words are treated the same, regardless of whether the lowercased version of the String has been seen). @return The wordshape String
private static String wordShapeDan1(String s) { boolean digit = true; boolean upper = true; boolean lower = true; boolean mixed = true; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (!Character.isDigit(c)) { digit = false; } if (!Character.isLowerCase(c)) { lower = false; } if (!Character.isUpperCase(c)) { upper = false; } if ((i == 0 && !Character.isUpperCase(c)) || (i >= 1 && !Character.isLowerCase(c))) { mixed = false; } } if (digit) { return "ALL-DIGITS"; } if (upper) { return "ALL-UPPER"; } if (lower) { return "ALL-LOWER"; } if (mixed) { return "MIXED-CASE"; } return "OTHER"; }
A fairly basic 5-way classifier, that notes digits, and upper and lower case, mixed, and non-alphanumeric. @param s String to find word shape of @return Its word shape: a 5 way classification
private static String wordShapeDan2(String s, Collection<String> knownLCWords) { StringBuilder sb = new StringBuilder("WT-"); char lastM = '~'; boolean nonLetters = false; int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); char m = c; if (Character.isDigit(c)) { m = 'd'; } else if (Character.isLowerCase(c) || c == '_') { m = 'x'; } else if (Character.isUpperCase(c)) { m = 'X'; } if (m != 'x' && m != 'X') { nonLetters = true; } if (m != lastM) { sb.append(m); } lastM = m; } if (len <= 3) { sb.append(':').append(len); } if (knownLCWords != null) { if (!nonLetters && knownLCWords.contains(s.toLowerCase())) { sb.append('k'); } } // System.err.println("wordShapeDan2: " + s + " became " + sb); return sb.toString(); }
A fine-grained word shape classifier, that equivalence classes lower and upper case and digits, and collapses sequences of the same type, but keeps all punctuation, etc. <p> <i>Note:</i> We treat '_' as a lowercase letter, sort of like many programming languages. We do this because we use '_' joining of tokens in some applications like RTE. @param s The String whose shape is to be returned @param knownLCWords If this is non-null and non-empty, mark words whose lower case form is found in the Collection of known lower case words @return The word shape
private static String wordShapeChris2(String s, boolean omitIfInBoundary, Collection<String> knownLCWords) { int len = s.length(); if (len <= BOUNDARY_SIZE * 2) { return wordShapeChris2Short(s, len, knownLCWords); } else { return wordShapeChris2Long(s, omitIfInBoundary, len, knownLCWords); } }
This one picks up on Dan2 ideas, but seeks to make less distinctions mid sequence by sorting for long words, but to maintain extra distinctions for short words. It exactly preserves the character shape of the first and last 2 (i.e., BOUNDARY_SIZE) characters and then will record shapes that occur between them (perhaps only if they are different) @param s The String to find the word shape of @param omitIfInBoundary If true, character classes present in the first or last two (i.e., BOUNDARY_SIZE) letters of the word are not also registered as classes that appear in the middle of the word. @param knownLCWords If non-null and non-empty, tag with a "k" suffix words that are in this list when lowercased (representing that the word is "known" as a lowercase word). @return A word shape for the word.
private static String wordShapeChris2Short(String s, int len, Collection<String> knownLCWords) { int sbLen = (knownLCWords != null) ? len + 1: len; // markKnownLC makes String 1 longer final StringBuilder sb = new StringBuilder(sbLen); boolean nonLetters = false; for (int i = 0; i < len; i++) { char c = s.charAt(i); char m = c; if (Character.isDigit(c)) { m = 'd'; } else if (Character.isLowerCase(c)) { m = 'x'; } else if (Character.isUpperCase(c) || Character.isTitleCase(c)) { m = 'X'; } for (String gr : greek) { if (s.startsWith(gr, i)) { m = 'g'; //System.out.println(s + " :: " + s.substring(i+1)); i += gr.length() - 1; // System.out.println("Position skips to " + i); break; } } if (m != 'x' && m != 'X') { nonLetters = true; } sb.append(m); } if (knownLCWords != null) { if ( ! nonLetters && knownLCWords.contains(s.toLowerCase())) { sb.append('k'); } } // System.out.println(s + " became " + sb); return sb.toString(); }
Do the simple case of words <= BOUNDARY_SIZE * 2 (i.e., 4) with only 1 object allocation!
private static String wordShapeChris2Long(String s, boolean omitIfInBoundary, int len, Collection<String> knownLCWords) { final char[] beginChars = new char[BOUNDARY_SIZE]; final char[] endChars = new char[BOUNDARY_SIZE]; int beginUpto = 0; int endUpto = 0; final Set<Character> seenSet = new TreeSet<Character>(); // TreeSet guarantees stable ordering; has no size parameter boolean nonLetters = false; for (int i = 0; i < len; i++) { int iIncr = 0; char c = s.charAt(i); char m = c; if (Character.isDigit(c)) { m = 'd'; } else if (Character.isLowerCase(c)) { m = 'x'; } else if (Character.isUpperCase(c) || Character.isTitleCase(c)) { m = 'X'; } for (String gr : greek) { if (s.startsWith(gr, i)) { m = 'g'; //System.out.println(s + " :: " + s.substring(i+1)); iIncr = gr.length() - 1; break; } } if (m != 'x' && m != 'X') { nonLetters = true; } if (i < BOUNDARY_SIZE) { beginChars[beginUpto++] = m; } else if (i < len - BOUNDARY_SIZE) { seenSet.add(Character.valueOf(m)); } else { endChars[endUpto++] = m; } i += iIncr; // System.out.println("Position skips to " + i); } // Calculate size. This may be an upperbound, but is often correct int sbSize = beginUpto + endUpto + seenSet.size(); if (knownLCWords != null) { sbSize++; } final StringBuilder sb = new StringBuilder(sbSize); // put in the beginning chars sb.append(beginChars, 0, beginUpto); // put in the stored ones sorted if (omitIfInBoundary) { for (Character chr : seenSet) { char ch = chr.charValue(); boolean insert = true; for (int i = 0; i < beginUpto; i++) { if (beginChars[i] == ch) { insert = false; break; } } for (int i = 0; i < endUpto; i++) { if (endChars[i] == ch) { insert = false; break; } } if (insert) { sb.append(ch); } } } else { for (Character chr : seenSet) { sb.append(chr.charValue()); } } // and add end ones sb.append(endChars, 0, endUpto); if (knownLCWords != null) { if (!nonLetters && knownLCWords.contains(s.toLowerCase())) { sb.append('k'); } } // System.out.println(s + " became " + sb); return sb.toString(); }
That is, of size 6, which become 8, since HashMaps are powers of 2. Still, it's half the size
private static String wordShapeChris4(String s, boolean omitIfInBoundary, Collection<String> knownLCWords) { int len = s.length(); if (len <= BOUNDARY_SIZE * 2) { return wordShapeChris4Short(s, len, knownLCWords); } else { return wordShapeChris4Long(s, omitIfInBoundary, len, knownLCWords); } }
This one picks up on Dan2 ideas, but seeks to make less distinctions mid sequence by sorting for long words, but to maintain extra distinctions for short words, by always recording the class of the first and last two characters of the word. Compared to chris2 on which it is based, it uses more Unicode classes, and so collapses things like punctuation more, and might work better with real unicode. @param s The String to find the word shape of @param omitIfInBoundary If true, character classes present in the first or last two (i.e., BOUNDARY_SIZE) letters of the word are not also registered as classes that appear in the middle of the word. @param knownLCWords If non-null and non-empty, tag with a "k" suffix words that are in this list when lowercased (representing that the word is "known" as a lowercase word). @return A word shape for the word.
private static String wordShapeChris4Short(String s, int len, Collection<String> knownLCWords) { int sbLen = (knownLCWords != null) ? len + 1: len; // markKnownLC makes String 1 longer final StringBuilder sb = new StringBuilder(sbLen); boolean nonLetters = false; for (int i = 0; i < len; i++) { char c = s.charAt(i); char m = chris4equivalenceClass(c); for (String gr : greek) { if (s.startsWith(gr, i)) { m = 'g'; //System.out.println(s + " :: " + s.substring(i+1)); i += gr.length() - 1; // System.out.println("Position skips to " + i); break; } } if (m != 'x' && m != 'X') { nonLetters = true; } sb.append(m); } if (knownLCWords != null) { if ( ! nonLetters && knownLCWords.contains(s.toLowerCase())) { sb.append('k'); } } // System.out.println(s + " became " + sb); return sb.toString(); }
Do the simple case of words <= BOUNDARY_SIZE * 2 (i.e., 4) with only 1 object allocation!
private static String wordShapeDan2Bio(String s, Collection<String> knownLCWords) { if (containsGreekLetter(s)) { return wordShapeDan2(s, knownLCWords) + "-GREEK"; } else { return wordShapeDan2(s, knownLCWords); } }
Returns a fine-grained word shape classifier, that equivalence classes lower and upper case and digits, and collapses sequences of the same type, but keeps all punctuation. This adds an extra recognizer for a greek letter embedded in the String, which is useful for bio.
private static boolean containsGreekLetter(String s) { Matcher m = biogreek.matcher(s); return m.find(); }
Somewhat ad-hoc list of only greek letters that bio people use, partly to avoid false positives on short ones. @param s String to check for Greek @return true iff there is a greek lette embedded somewhere in the String
private static String wordShapeChris1(String s) { int length = s.length(); if (length == 0) { return "SYMBOL"; // unclear if this is sensible, but it's what a length 0 String becomes.... } boolean cardinal = false; boolean number = true; boolean seenDigit = false; boolean seenNonDigit = false; for (int i = 0; i < length; i++) { char ch = s.charAt(i); boolean digit = Character.isDigit(ch); if (digit) { seenDigit = true; } else { seenNonDigit = true; } // allow commas, decimals, and negative numbers digit = digit || ch == '.' || ch == ',' || (i == 0 && (ch == '-' || ch == '+')); if (!digit) { number = false; } } if ( ! seenDigit) { number = false; } else if ( ! seenNonDigit) { cardinal = true; } if (cardinal) { if (length < 4) { return "CARDINAL13"; } else if (length == 4) { return "CARDINAL4"; } else { return "CARDINAL5PLUS"; } } else if (number) { return "NUMBER"; } boolean seenLower = false; boolean seenUpper = false; boolean allCaps = true; boolean allLower = true; boolean initCap = false; boolean dash = false; boolean period = false; for (int i = 0; i < length; i++) { char ch = s.charAt(i); boolean up = Character.isUpperCase(ch); boolean let = Character.isLetter(ch); boolean tit = Character.isTitleCase(ch); if (ch == '-') { dash = true; } else if (ch == '.') { period = true; } if (tit) { seenUpper = true; allLower = false; seenLower = true; allCaps = false; } else if (up) { seenUpper = true; allLower = false; } else if (let) { seenLower = true; allCaps = false; } if (i == 0 && (up || tit)) { initCap = true; } } if (length == 2 && initCap && period) { return "ACRONYM1"; } else if (seenUpper && allCaps && !seenDigit && period) { return "ACRONYM"; } else if (seenDigit && dash && !seenUpper && !seenLower) { return "DIGIT-DASH"; } else if (initCap && seenLower && seenDigit && dash) { return "CAPITALIZED-DIGIT-DASH"; } else if (initCap && seenLower && seenDigit) { return "CAPITALIZED-DIGIT"; } else if (initCap && seenLower && dash) { return "CAPITALIZED-DASH"; } else if (initCap && seenLower) { return "CAPITALIZED"; } else if (seenUpper && allCaps && seenDigit && dash) { return "ALLCAPS-DIGIT-DASH"; } else if (seenUpper && allCaps && seenDigit) { return "ALLCAPS-DIGIT"; } else if (seenUpper && allCaps && dash) { return "ALLCAPS"; } else if (seenUpper && allCaps) { return "ALLCAPS"; } else if (seenLower && allLower && seenDigit && dash) { return "LOWERCASE-DIGIT-DASH"; } else if (seenLower && allLower && seenDigit) { return "LOWERCASE-DIGIT"; } else if (seenLower && allLower && dash) { return "LOWERCASE-DASH"; } else if (seenLower && allLower) { return "LOWERCASE"; } else if (seenLower && seenDigit) { return "MIXEDCASE-DIGIT"; } else if (seenLower) { return "MIXEDCASE"; } else if (seenDigit) { return "SYMBOL-DIGIT"; } else { return "SYMBOL"; } }
This one equivalence classes all strings into one of 24 semantically informed classes, somewhat similarly to the function specified in the BBN Nymble NER paper (Bikel et al. 1997). <p> Note that it regards caseless non-Latin letters as lowercase. @param s String to word class @return The string's class
private static String wordShapeDigits(final String s) { char[] outChars = null; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isDigit(c)) { if (outChars == null) { outChars = s.toCharArray(); } outChars[i] = '9'; } } if (outChars == null) { // no digit found return s; } else { return new String(outChars); } }
Just collapses digits to 9 characters. Does lazy copying of String. @param s String to find word shape of @return The same string except digits are equivalence classed to 9.
public static void main(String[] args) { int i = 0; int classifierToUse = WORDSHAPECHRIS1; if (args.length == 0) { System.out.println("edu.stanford.nlp.process.WordShapeClassifier [-wordShape name] string+"); } else if (args[0].charAt(0) == '-') { if (args[0].equals("-wordShape") && args.length >= 2) { classifierToUse = lookupShaper(args[1]); i += 2; } else { System.err.println("Unknown flag: " + args[0]); i++; } } for (; i < args.length; i++) { System.out.print(args[i] + ": "); System.out.println(wordShape(args[i], classifierToUse)); } }
Usage: <code>java edu.stanford.nlp.process.WordShapeClassifier [-wordShape name] string+ </code><br> where <code>name</code> is an argument to <code>lookupShaper</code>. Known names have patterns along the lines of: dan[12](bio)?(UseLC)?, jenny1(useLC)?, chris[1234](useLC)?. If you don't specify a word shape function, you get chris1. @param args Command-line arguments, as above.
public static aaagroup_authorizationpolicy_binding[] get(nitro_service service, String groupname) throws Exception{ aaagroup_authorizationpolicy_binding obj = new aaagroup_authorizationpolicy_binding(); obj.set_groupname(groupname); aaagroup_authorizationpolicy_binding response[] = (aaagroup_authorizationpolicy_binding[]) obj.get_resources(service); return response; }
Use this API to fetch aaagroup_authorizationpolicy_binding resources of given name .
public static cachepolicylabel_policybinding_binding[] get(nitro_service service, String labelname) throws Exception{ cachepolicylabel_policybinding_binding obj = new cachepolicylabel_policybinding_binding(); obj.set_labelname(labelname); cachepolicylabel_policybinding_binding response[] = (cachepolicylabel_policybinding_binding[]) obj.get_resources(service); return response; }
Use this API to fetch cachepolicylabel_policybinding_binding resources of given name .
public static csvserver_copolicy_binding[] get(nitro_service service, String name) throws Exception{ csvserver_copolicy_binding obj = new csvserver_copolicy_binding(); obj.set_name(name); csvserver_copolicy_binding response[] = (csvserver_copolicy_binding[]) obj.get_resources(service); return response; }
Use this API to fetch csvserver_copolicy_binding resources of given name .
protected base_resource[] get_nitro_response(nitro_service service, String response) throws Exception { ipseccounters_stats[] resources = new ipseccounters_stats[1]; ipseccounters_response result = (ipseccounters_response) service.get_payload_formatter().string_to_resource(ipseccounters_response.class, response); if(result.errorcode != 0) { if (result.errorcode == 444) { service.clear_session(); } if(result.severity != null) { if (result.severity.equals("ERROR")) throw new nitro_exception(result.message,result.errorcode); } else { throw new nitro_exception(result.message,result.errorcode); } } resources[0] = result.ipseccounters; return resources; }
<pre> converts nitro response into object and returns the object array in case of get request. </pre>
public static ipseccounters_stats get(nitro_service service) throws Exception{ ipseccounters_stats obj = new ipseccounters_stats(); ipseccounters_stats[] response = (ipseccounters_stats[])obj.stat_resources(service); return response[0]; }
Use this API to fetch the statistics of all ipseccounters_stats resources that are configured on netscaler.
public RedwoodConfiguration clear(){ tasks = new LinkedList<Runnable>(); tasks.add(new Runnable(){ public void run(){ Redwood.clearHandlers(); Redwood.restoreSystemStreams(); Redwood.clearLoggingClasses(); } }); return this; }
Clear any custom configurations to Redwood @return this
public RedwoodConfiguration stdout(){ LogRecordHandler visibility = new VisibilityHandler(); LogRecordHandler console = Redwood.ConsoleHandler.out(); return this .rootHandler(visibility) .handler(visibility, console); }
Add a console pipeline to the Redwood handler tree, printing to stdout. Calling this multiple times will result in messages being printed multiple times. @return this
public RedwoodConfiguration stderr(){ LogRecordHandler visibility = new VisibilityHandler(); LogRecordHandler console = Redwood.ConsoleHandler.err(); return this .rootHandler(visibility) .handler(visibility, console); }
Add a console pipeline to the Redwood handler tree, printing to stderr. Calling this multiple times will result in messages being printed multiple times. @return this
public RedwoodConfiguration file(String file){ LogRecordHandler visibility = new VisibilityHandler(); LogRecordHandler console = new Redwood.FileHandler(file); return this .rootHandler(visibility) .handler(visibility, console); }
Add a file pipeline to the Redwood handler tree. That is, print log messages to a given file. Calling this multiple times will result in messages being printed to multiple files (or, multiple times to the same file). @param file The path of the file to log to. This path is not checked for correctness here. @return this
public RedwoodConfiguration rootHandler(final LogRecordHandler handler){ tasks.add(new Runnable(){ public void run(){ Redwood.appendHandler(handler); } }); Redwood.appendHandler(handler); return this; }
Add a custom Log Record Handler to the root of the tree @param handler The handler to add @return this
public RedwoodConfiguration handler(final LogRecordHandler parent, final LogRecordHandler child){ tasks.add(new Runnable() { public void run() { Redwood.appendHandler(parent, child);} }); return this; }
Add a handler to as a child of an existing parent @param parent The handler to extend @param child The new handler to add @return this
public RedwoodConfiguration splice(final LogRecordHandler parent, final LogRecordHandler toAdd, final LogRecordHandler grandchild){ tasks.add(new Runnable() { public void run() { Redwood.spliceHandler(parent, toAdd, grandchild);} }); return this; }
Add a handler to as a child of an existing parent @param parent The handler to extend @param toAdd The new handler to add @param grandchild The subtree to attach to the new handler @return this
public RedwoodConfiguration loggingClass(final String classToIgnoreInTraces){ tasks.add(new Runnable() { public void run() { Redwood.addLoggingClass(classToIgnoreInTraces); } }); return this; }
Set a Java classname path to ignore when printing stack traces @param classToIgnoreInTraces The class name (with packages, etc) to ignore. @return this
public RedwoodConfiguration loggingClass(final Class<?> classToIgnoreInTraces){ tasks.add(new Runnable() { public void run() { Redwood.addLoggingClass(classToIgnoreInTraces.getName()); } }); return this; }
Set a Java class to ignore when printing stack traces @param classToIgnoreInTraces The class to ignore. @return this
public RedwoodConfiguration collapseApproximate(){ tasks.add(new Runnable() { public void run() { Redwood.spliceHandler(VisibilityHandler.class, new RepeatedRecordHandler(RepeatedRecordHandler.APPROXIMATE),OutputHandler.class); } }); return this; }
Collapse repeated records, using an approximate notion of equality (i.e. records begin or end with the same substring) This is useful for cases such as tracking iterations ("iter 1" and "iter 2" are considered the same record). @return this
public RedwoodConfiguration collapseExact(){ tasks.add(new Runnable() { public void run() { Redwood.spliceHandler(VisibilityHandler.class, new RepeatedRecordHandler(RepeatedRecordHandler.EXACT), OutputHandler.class); } }); return this; }
Collapse repeated records, using exact string match on the record. This is generally useful for making very verbose logs more readable. @return this
public RedwoodConfiguration captureStdout(){ tasks.add(new Runnable() { public void run() { Redwood.captureSystemStreams(true, false); } }); return this; }
Capture stdout and route them through Redwood @return this
public RedwoodConfiguration neatExit(){ tasks.add(new Runnable() { public void run() { Runtime.getRuntime().addShutdownHook(new Thread(){ @Override public void run(){ Redwood.stop(); } }); }}); return this; }
Close tracks when the JVM shuts down. @return this
public RedwoodConfiguration printChannels(final int width){ tasks.add(new Runnable() { public void run() { Redwood.Util.printChannels(width);} }); return this; }
Print channels to the left of log messages @param width The width (in characters) to print the channels @return this
public RedwoodConfiguration hideChannels(final Object[] channels){ tasks.add(new Runnable() { public void run() { Redwood.hideChannels(channels); } }); return this; }
Hide the following channels. @param channels The names of the channels to hide. @return this
public RedwoodConfiguration showOnlyChannels(final Object[] channels){ tasks.add(new Runnable() { public void run() { Redwood.showOnlyChannels(channels); } }); return this; }
Show only the following channels. @param channels The names of the channels to show. @return this
private static String get(Properties p, String key, String defaultValue, Set<String> used){ String rtn = p.getProperty(key, defaultValue); used.add(key); return rtn; }
Helper for parsing properties @param p The properties object @param key The key to retrieve @param defaultValue The default value if the key does not exist @param used The set of keys we have seen @return The value of the property at the key
public static RedwoodConfiguration parse(Properties props){ Set<String> used = new HashSet<String>(); //--Construct Pipeline //(handlers) Redwood.ConsoleHandler console = get(props,"log.toStderr","false",used).equalsIgnoreCase("true") ? Redwood.ConsoleHandler.err() : Redwood.ConsoleHandler.out(); VisibilityHandler visibility = new VisibilityHandler(); RepeatedRecordHandler repeat = null; //(initialize pipeline) RedwoodConfiguration config = new RedwoodConfiguration().clear().rootHandler(visibility); //(collapse) String collapseSetting = get(props,"log.collapse","none",used); if(collapseSetting.equalsIgnoreCase("exact")){ repeat = new RepeatedRecordHandler(RepeatedRecordHandler.EXACT); config = config.handler(visibility,repeat); } else if(collapseSetting.equalsIgnoreCase("approximate")){ repeat = new RepeatedRecordHandler(RepeatedRecordHandler.APPROXIMATE); config = config.handler(visibility, repeat); } else if(collapseSetting.equalsIgnoreCase("none")){ //do nothing } else { throw new IllegalArgumentException("Unknown collapse type: " + collapseSetting); } //--Console config.handler(repeat == null ? visibility : repeat, console); //((track color)) console.trackColor = Color.valueOf(get(props,"log.console.trackColor","NONE",used).toUpperCase()); console.trackStyle = Style.valueOf(get(props,"log.console.trackStyle","NONE",used).toUpperCase()); //((other colors)) for(Object propAsObj : props.keySet()) { String prop = propAsObj.toString(); // color Matcher m = consoleColor.matcher(prop); if(m.find()){ String channel = m.group(1); console.colorChannel(channel, Color.valueOf(get(props,prop,"NONE",used))); } // style m = consoleStyle.matcher(prop); if(m.find()){ String channel = m.group(1); console.styleChannel(channel, Style.valueOf(get(props,prop,"NONE",used))); } } //((random colors)) console.setColorChannels(Boolean.parseBoolean(get(props, "log.console.colorChannels", "false", used))); //--File String logFilename = get(props,"log.file",null,used); if(logFilename != null){ Redwood.FileHandler file = new Redwood.FileHandler(logFilename); config.handler(repeat == null ? visibility : repeat, file); //((track colors)) file.trackColor = Color.valueOf(get(props,"log.file.trackColor","NONE",used).toUpperCase()); file.trackStyle = Style.valueOf(get(props,"log.file.trackStyle","NONE",used).toUpperCase()); //((other colors)) for(Object propAsObj : props.keySet()) { String prop = propAsObj.toString(); // color Matcher m = fileColor.matcher(prop); if(m.find()){ String channel = m.group(1); file.colorChannel(channel, Color.valueOf(get(props,prop,"NONE",used))); } // style m = fileStyle.matcher(prop); if(m.find()){ String channel = m.group(1); file.styleChannel(channel, Style.valueOf(get(props,prop,"NONE",used))); } } //((random colors)) file.setColorChannels(Boolean.parseBoolean(get(props,"log.file.colorChannels","false",used))); } //--System Streams if(get(props,"log.captureStreams","false",used).equalsIgnoreCase("true")){ config = config.captureStreams(); } if(get(props,"log.captureStdout","false",used).equalsIgnoreCase("true")){ config = config.captureStdout(); } if(get(props,"log.captureStderr","false",used).equalsIgnoreCase("true")){ config = config.captureStderr(); } //--Neat exit if(get(props,"log.neatExit","false",used).equalsIgnoreCase("true")){ config = config.neatExit(); } String channelsToShow = get(props,"log.showOnlyChannels",null,used); String channelsToHide = get(props,"log.hideChannels",null,used); if (channelsToShow != null && channelsToHide != null) { throw new IllegalArgumentException("Can't specify both log.showOnlyChannels and log.hideChannels"); } //--Channel visibility if (channelsToShow != null) { config = config.showOnlyChannels(channelsToShow.split(",")); } else if (channelsToHide != null) { config = config.hideChannels(channelsToHide.split(",")); } //--Error Check for(Object propAsObj : props.keySet()) { String prop = propAsObj.toString(); if(prop.startsWith("log.") && !used.contains(prop)){ throw new IllegalArgumentException("Could not find Redwood log property: " + prop); } } //--Return return config; }
Configure Redwood (from scratch) based on a Properties file. Currently recognized properties are: <ul> <li>log.toStderr = {true,false}: Print to stderr rather than stdout</li> <li>log.file = [filename]: Dump the output of the log to the given filename</li> <li>log.collapse = {exact,approximate,none}: Collapse repeated records (based on either exact or approximate equality)</li> <li>log.neatExit = {true,false}: Clean up logs on exception or regular system exit <li>log.{console,file}.colorChannels = {true,false}: If true, randomly assign colors to different channels</li> <li>log.{console,file}.{track,[channel]}]Color = {NONE,BLACK,RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE}: Color for printing tracks (e.g. log.file.trackColor = BLUE) <li>log.{console,file}.{track,[channel]}Style = {NONE,BOLD,DIM,ITALIC,UNDERLINE,BLINK,CROSS_OUT}: Style for printing tracks (e.g. log.console.errStyle = BOLD) <li>log.captureStreams = {true,false}: Capture stdout and stderr and route them through Redwood</li> <li>log.captureStdout = {true,false}: Capture stdout and route it through Redwood</li> <li>log.captureStderr = {true,false}: Capture stdout and route it through Redwood</li> <li>log.hideChannels = [channels]: Hide these channels (comma-separated list)</li> <li>log.showOnlyChannels = [channels]: Show only these channels (comma-separated list)</li> </ul> @param props The properties to use in configuration @return A new Redwood Configuration based on the passed properties, ignoring any existing custom configuration
public static vpnglobal_auditnslogpolicy_binding[] get(nitro_service service) throws Exception{ vpnglobal_auditnslogpolicy_binding obj = new vpnglobal_auditnslogpolicy_binding(); vpnglobal_auditnslogpolicy_binding response[] = (vpnglobal_auditnslogpolicy_binding[]) obj.get_resources(service); return response; }
Use this API to fetch a vpnglobal_auditnslogpolicy_binding resources.
public static vpnglobal_auditnslogpolicy_binding[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception{ vpnglobal_auditnslogpolicy_binding obj = new vpnglobal_auditnslogpolicy_binding(); options option = new options(); option.set_filter(filter); vpnglobal_auditnslogpolicy_binding[] response = (vpnglobal_auditnslogpolicy_binding[]) obj.getfiltered(service, option); return response; }
Use this API to fetch filtered set of vpnglobal_auditnslogpolicy_binding resources. set the filter parameter values in filtervalue object.
private double[][] _start() { double[][] startState = new double[2][]; startState[0] = new double[initialState.length]; startState[1] = Arrays.copyOf(initialState, initialState.length); return startState; }
Start. @return the double[][]
private double[][] _step(double[][] state, char ch1) { double cost; _shift(state); state[1][0] = state[0][0] + deletionDistance; for (int i = 0; i < base.length(); i++) { cost = (base.charAt(i) == ch1) ? 0 : replaceDistance; state[1][i + 1] = Math.min(state[1][i] + insertionDistance, state[0][i] + cost); state[1][i + 1] = Math.min(state[1][i + 1], state[0][i + 1] + deletionDistance); } return state; }
Step. @param state the state @param ch1 the ch 1 @return the double[][]
public static filterpolicy_csvserver_binding[] get(nitro_service service, String name) throws Exception{ filterpolicy_csvserver_binding obj = new filterpolicy_csvserver_binding(); obj.set_name(name); filterpolicy_csvserver_binding response[] = (filterpolicy_csvserver_binding[]) obj.get_resources(service); return response; }
Use this API to fetch filterpolicy_csvserver_binding resources of given name .
public static TreeGraphNode getSubject(TreeGraphNode t) { TreeGraphNode subj = getNodeInRelation(t, NOMINAL_SUBJECT); if (subj != null) { return subj; } subj = getNodeInRelation(t, CLAUSAL_SUBJECT); if (subj != null) { return subj; } else { return getNodeInRelation(t, NOMINAL_PASSIVE_SUBJECT); } }
Tries to return a node representing the <code>SUBJECT</code> (whether nominal or clausal) of the given node <code>t</code>. Probably, node <code>t</code> should represent a clause or verb phrase. @param t a node in this <code>GrammaticalStructure</code> @return a node which is the subject of node <code>t</code>, or else <code>null</code>
@Override protected void collapseDependencies(List<TypedDependency> list, boolean CCprocess) { if (DEBUG) { printListSorted("collapseDependencies: CCproc: " + CCprocess, list); } correctDependencies(list); if (DEBUG) { printListSorted("After correctDependencies:", list); } eraseMultiConj(list); if (DEBUG) { printListSorted("After collapse multi conj:", list); } collapse2WP(list); if (DEBUG) { printListSorted("After collapse2WP:", list); } collapseFlatMWP(list); if (DEBUG) { printListSorted("After collapseFlatMWP:", list); } collapse2WPbis(list); if (DEBUG) { printListSorted("After collapse2WPbis:", list); } collapse3WP(list); if (DEBUG) { printListSorted("After collapse3WP:", list); } collapsePrepAndPoss(list); if (DEBUG) { printListSorted("After PrepAndPoss:", list); } collapseConj(list); if (DEBUG) { printListSorted("After conj:", list); } collapseReferent(list); if (DEBUG) { printListSorted("After collapse referent:", list); } if (CCprocess) { treatCC(list); if (DEBUG) { printListSorted("After treatCC:", list); } } removeDep(list); if (DEBUG) { printListSorted("After remove dep:", list); } Collections.sort(list); if (DEBUG) { printListSorted("After all collapse:", list); } }
Destructively modifies this <code>Collection&lt;TypedDependency&gt;</code> by collapsing several types of transitive pairs of dependencies. <dl> <dt>prepositional object dependencies: pobj</dt> <dd> <code>prep(cat, in)</code> and <code>pobj(in, hat)</code> are collapsed to <code>prep_in(cat, hat)</code></dd> <dt>prepositional complement dependencies: pcomp</dt> <dd> <code>prep(heard, of)</code> and <code>pcomp(of, attacking)</code> are collapsed to <code>prepc_of(heard, attacking)</code></dd> <dt>conjunct dependencies</dt> <dd> <code>cc(investors, and)</code> and <code>conj(investors, regulators)</code> are collapsed to <code>conj_and(investors,regulators)</code></dd> <dt>possessive dependencies: possessive</dt> <dd> <code>possessive(Montezuma, 's)</code> will be erased. This is like a collapsing, but due to the flatness of NPs, two dependencies are not actually composed.</dd> <dt>For relative clauses, it will collapse referent</dt> <dd> <code>ref(man, that)</code> and <code>dobj(love, that)</code> are collapsed to <code>dobj(love, man)</code></dd> </dl>
@Override protected void collapseDependenciesTree(List<TypedDependency> list) { correctDependencies(list); if (DEBUG) { printListSorted("After correctDependencies:", list); } eraseMultiConj(list); if (DEBUG) { printListSorted("After collapse multi conj:", list); } collapse2WP(list); if (DEBUG) { printListSorted("After collapse2WP:", list); } collapseFlatMWP(list); if (DEBUG) { printListSorted("After collapseFlatMWP:", list); } collapse2WPbis(list); if (DEBUG) { printListSorted("After collapse2WPbis:", list); } collapse3WP(list); if (DEBUG) { printListSorted("After collapse3WP:", list); } collapsePrepAndPoss(list); if (DEBUG) { printListSorted("After PrepAndPoss:", list); } collapseConj(list); if (DEBUG) { printListSorted("After conj:", list); } Collections.sort(list); if (DEBUG) { printListSorted("After all collapse:", list); } }
Destructively modifies this <code>Collection&lt;TypedDependency&gt;</code> by collapsing several types of transitive pairs of dependencies, but keeping the tree structure. <dl> <dt>prepositional object dependencies: pobj</dt> <dd> <code>prep(cat, in)</code> and <code>pobj(in, hat)</code> are collapsed to <code>prep_in(cat, hat)</code></dd> <dt>prepositional complement dependencies: pcomp</dt> <dd> <code>prep(heard, of)</code> and <code>pcomp(of, attacking)</code> are collapsed to <code>prepc_of(heard, attacking)</code></dd> <dt>conjunct dependencies</dt> <dd> <code>cc(investors, and)</code> and <code>conj(investors, regulators)</code> are collapsed to <code>conj_and(investors,regulators)</code></dd> <dt>possessive dependencies: possessive</dt> <dd> <code>possessive(Montezuma, 's)</code> will be erased. This is like a collapsing, but due to the flatness of NPs, two dependencies are not actually composed.</dd>
protected static GrammaticalRelation conjValue(String conj) { String newConj = conj.toLowerCase(); if (newConj.equals("not") || newConj.equals("instead") || newConj.equals("rather")) { newConj = "negcc"; } else if (newConj.equals("mention") || newConj.equals("to") || newConj.equals("also") || newConj.contains("well") || newConj.equals("&")) { newConj = "and"; } return EnglishGrammaticalRelations.getConj(newConj); }
Does some hard coding to deal with relation in CONJP. For now we deal with: but not, if not, instead of, rather than, but rather GO TO negcc as well as, not to mention, but also, & GO TO and. @param conj The head dependency of the conjunction marker @return A GrammaticalRelation made from a normalized form of that conjunction.
private static void collapseConj(Collection<TypedDependency> list) { List<TreeGraphNode> govs = new ArrayList<TreeGraphNode>(); // find typed deps of form cc(gov, dep) for (TypedDependency td : list) { if (td.reln() == COORDINATION) { // i.e. "cc" TreeGraphNode gov = td.gov(); GrammaticalRelation conj = conjValue(td.dep().value()); if (DEBUG) { System.err.println("Set conj to " + conj + " based on " + td); } // find other deps of that gov having reln "conj" boolean foundOne = false; for (TypedDependency td1 : list) { if (td1.gov() == gov) { if (td1.reln() == CONJUNCT) { // i.e., "conj" // change "conj" to the actual (lexical) conjunction if (DEBUG) { System.err.println("Changing " + td1 + " to have relation " + conj); } td1.setReln(conj); foundOne = true; } else if (td1.reln() == COORDINATION) { conj = conjValue(td1.dep().value()); if (DEBUG) { System.err.println("Set conj to " + conj + " based on " + td1); } } } } // register to remove cc from this governor if (foundOne) { govs.add(gov); } } } // now remove typed dependencies with reln "cc" if we have successfully // collapsed for (Iterator<TypedDependency> iter = list.iterator(); iter.hasNext();) { TypedDependency td2 = iter.next(); if (td2.reln() == COORDINATION && govs.contains(td2.gov())) { iter.remove(); } } }
This rewrites the "conj" relation to "conj_word" and deletes cases of the "cc" relation providing this rewrite has occurred (but not if there is only something like a clause-initial and). For instance, cc(elected-5, and-9) conj(elected-5, re-elected-11) becomes conj_and(elected-5, re-elected-11) @param list List of dependencies.
private static void collapseReferent(Collection<TypedDependency> list) { // find typed deps of form ref(gov, dep) // put them in a List for processing; remove them from the set of deps List<TypedDependency> refs = new ArrayList<TypedDependency>(); for (Iterator<TypedDependency> iter = list.iterator(); iter.hasNext();) { TypedDependency td = iter.next(); if (td.reln() == REFERENT) { refs.add(td); iter.remove(); } } // now substitute target of referent where possible for (TypedDependency ref : refs) { TreeGraphNode dep = ref.dep();// take the relative word TreeGraphNode ant = ref.gov();// take the antecedent for (TypedDependency td : list) { // the last condition below maybe shouldn't be necessary, but it has // helped stop things going haywire a couple of times (it stops the // creation of a unit cycle that probably leaves something else // disconnected) [cdm Jan 2010] if (td.dep() == dep && td.reln() != RELATIVE && td.reln() != REFERENT && td.gov() != ant) { if (DEBUG) System.err.print("referent: changing " + td); td.setDep(ant); if (DEBUG) System.err.println(" to " + td); } } } }
This method will collapse a referent relation such as follows. e.g.: "The man that I love ... " ref(man, that) dobj(love, that) -> dobj(love, man)
private static void correctSubjPassAndPoss(Collection<TypedDependency> list) { // put in a list verbs having an auxpass List<TreeGraphNode> list_auxpass = new ArrayList<TreeGraphNode>(); for (TypedDependency td : list) { if (td.reln() == AUX_PASSIVE_MODIFIER) { list_auxpass.add(td.gov()); } } for (TypedDependency td : list) { // correct nsubj if (td.reln() == NOMINAL_SUBJECT && list_auxpass.contains(td.gov())) { // System.err.println("%%% Changing subj to passive: " + td); td.setReln(NOMINAL_PASSIVE_SUBJECT); } if (td.reln() == CLAUSAL_SUBJECT && list_auxpass.contains(td.gov())) { // System.err.println("%%% Changing subj to passive: " + td); td.setReln(CLAUSAL_PASSIVE_SUBJECT); } // correct unretrieved poss: dep relation in which the dependent is a // PRP$ or WP$ // cdm: Now done in basic rules. The only cases that this still matches // are (1) tagging mistakes where PRP in dobj position is mistagged PRP$ // or a couple of parsing errors where the dependency is wrong anyway, so // it's probably okay to keep it a dep. So I'm disabling this. // String tag = td.dep().parent().value(); // if (td.reln() == DEPENDENT && (tag.equals("PRP$") || tag.equals("WP$"))) { // System.err.println("%%% Unrecognized basic possessive pronoun: " + td); // td.setReln(POSSESSION_MODIFIER); // } } }
This method corrects subjects of verbs for which we identified an auxpass, but didn't identify the subject as passive. It also corrects the possessive relations for PRP$ and WP$ which weren't retrieved. @param list List of typedDependencies to work on
private static GrammaticalRelation determinePrepRelation(Map<TreeGraphNode, ? extends Set<TypedDependency>> map, List<TreeGraphNode> partmod, TypedDependency pc, TypedDependency topPrep, boolean pobj) { // handling the case of an "agent": // the governor of a "by" preposition must have an "auxpass" dependency // or be the dependent of a "partmod" relation // if it is the case, the "agent" variable becomes true boolean agent = false; String preposition = pc.dep().value().toLowerCase(); if (preposition.equals("by")) { // look if we have an auxpass Set<TypedDependency> aux_pass_poss = map.get(topPrep.gov()); if (aux_pass_poss != null) { for (TypedDependency td_pass : aux_pass_poss) { if (td_pass.reln() == AUX_PASSIVE_MODIFIER) { agent = true; } } } // look if we have a partmod if (!partmod.isEmpty() && partmod.contains(topPrep.gov())) { agent = true; } } GrammaticalRelation reln; if (agent) { reln = AGENT; } else if (pc.reln() == RELATIVE) { reln = RELATIVE; } else { // for prepositions, use the preposition // for pobj: we collapse into "prep"; for pcomp: we collapse into "prepc" if (pobj) { reln = EnglishGrammaticalRelations.getPrep(preposition); } else { reln = EnglishGrammaticalRelations.getPrepC(preposition); } } return reln; }
Work out prep relation name. pc is the dependency whose dep() is the preposition to do a name for. topPrep may be the same or different. Among the daughters of its gov is where to look for an auxpass.
private static boolean isConjWithNoPrep(TreeGraphNode node, Collection<TypedDependency> list) { for (TypedDependency td : list) { if (td.gov() == node && td.reln() == CONJUNCT) { // we have a conjunct // check the POS of the dependent String tdDepPOS = td.dep().parent().value(); if (!(tdDepPOS.equals("IN") || tdDepPOS.equals("TO"))) { return true; } } } return false; }
Given a list of typedDependencies, returns true if the node "node" is the governor of a conj relation with a dependent which is not a preposition @param node A node in this GrammaticalStructure @param list A list of typedDependencies @return true If node is the governor of a conj relation in the list with the dep not being a preposition
private static void collapse2WP(Collection<TypedDependency> list) { Collection<TypedDependency> newTypedDeps = new ArrayList<TypedDependency>(); for (String[] mwp : MULTIWORD_PREPS) { // first look for patterns such as: // X(gov, mwp[0]) // Y(mpw[0],mwp[1]) // Z(mwp[1], compl) or Z(mwp[0], compl) // -> prep_mwp[0]_mwp[1](gov, compl) collapseMultiWordPrep(list, newTypedDeps, mwp[0], mwp[1], mwp[0], mwp[1]); // now look for patterns such as: // X(gov, mwp[1]) // Y(mpw[1],mwp[0]) // Z(mwp[1], compl) or Z(mwp[0], compl) // -> prep_mwp[0]_mwp[1](gov, compl) collapseMultiWordPrep(list, newTypedDeps, mwp[0], mwp[1], mwp[1], mwp[0]); } }
Collapse multiword preposition of the following format: prep|advmod|dep|amod(gov, mwp[0]) <br/> dep(mpw[0],mwp[1]) <br/> pobj|pcomp(mwp[1], compl) or pobj|pcomp(mwp[0], compl) <br/> -> prep_mwp[0]_mwp[1](gov, compl) <br/> prep|advmod|dep|amod(gov, mwp[1]) <br/> dep(mpw[1],mwp[0]) <br/> pobj|pcomp(mwp[1], compl) or pobj|pcomp(mwp[0], compl) <br/> -> prep_mwp[0]_mwp[1](gov, compl) <p/> The collapsing has to be done at once in order to know exactly which node is the gov and the dep of the multiword preposition. Otherwise this can lead to problems: removing a non-multiword "to" preposition for example!!! This method replaces the old "collapsedMultiWordPreps" @param list list of typedDependencies to work on