idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
20,900 | public String getReferenceText ( ) { if ( DataTable_Type . featOkTst && ( ( DataTable_Type ) jcasType ) . casFeat_referenceText == null ) jcasType . jcas . throwFeatMissing ( "referenceText" , "ch.epfl.bbp.uima.types.DataTable" ) ; return jcasType . ll_cas . ll_getStringValue ( addr , ( ( DataTable_Type ) jcasType ) . casFeatCode_referenceText ) ; } | getter for referenceText - gets |
20,901 | public void setReferenceText ( String v ) { if ( DataTable_Type . featOkTst && ( ( DataTable_Type ) jcasType ) . casFeat_referenceText == null ) jcasType . jcas . throwFeatMissing ( "referenceText" , "ch.epfl.bbp.uima.types.DataTable" ) ; jcasType . ll_cas . ll_setStringValue ( addr , ( ( DataTable_Type ) jcasType ) . casFeatCode_referenceText , v ) ; } | setter for referenceText - sets |
20,902 | public int getPageNumber ( ) { if ( DataTable_Type . featOkTst && ( ( DataTable_Type ) jcasType ) . casFeat_pageNumber == null ) jcasType . jcas . throwFeatMissing ( "pageNumber" , "ch.epfl.bbp.uima.types.DataTable" ) ; return jcasType . ll_cas . ll_getIntValue ( addr , ( ( DataTable_Type ) jcasType ) . casFeatCode_pageNumber ) ; } | getter for pageNumber - gets the number of the page where the table is located in |
20,903 | public void setPageNumber ( int v ) { if ( DataTable_Type . featOkTst && ( ( DataTable_Type ) jcasType ) . casFeat_pageNumber == null ) jcasType . jcas . throwFeatMissing ( "pageNumber" , "ch.epfl.bbp.uima.types.DataTable" ) ; jcasType . ll_cas . ll_setIntValue ( addr , ( ( DataTable_Type ) jcasType ) . casFeatCode_pageNumber , v ) ; } | setter for pageNumber - sets the number of the page where the table is located in |
20,904 | public FSArray getWordForms ( ) { if ( Token_Type . featOkTst && ( ( Token_Type ) jcasType ) . casFeat_wordForms == null ) jcasType . jcas . throwFeatMissing ( "wordForms" , "com.digitalpebble.rasp.Token" ) ; return ( FSArray ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Token_Type ) jcasType ) . casFeatCode_wordForms ) ) ) ; } | getter for wordForms - gets A Token is related to one or more WordForm |
20,905 | public void setWordForms ( FSArray v ) { if ( Token_Type . featOkTst && ( ( Token_Type ) jcasType ) . casFeat_wordForms == null ) jcasType . jcas . throwFeatMissing ( "wordForms" , "com.digitalpebble.rasp.Token" ) ; jcasType . ll_cas . ll_setRefValue ( addr , ( ( Token_Type ) jcasType ) . casFeatCode_wordForms , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | setter for wordForms - sets A Token is related to one or more WordForm |
20,906 | public WordForm getWordForms ( int i ) { if ( Token_Type . featOkTst && ( ( Token_Type ) jcasType ) . casFeat_wordForms == null ) jcasType . jcas . throwFeatMissing ( "wordForms" , "com.digitalpebble.rasp.Token" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Token_Type ) jcasType ) . casFeatCode_wordForms ) , i ) ; return ( WordForm ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Token_Type ) jcasType ) . casFeatCode_wordForms ) , i ) ) ) ; } | indexed getter for wordForms - gets an indexed value - A Token is related to one or more WordForm |
20,907 | public void setWordForms ( int i , WordForm v ) { if ( Token_Type . featOkTst && ( ( Token_Type ) jcasType ) . casFeat_wordForms == null ) jcasType . jcas . throwFeatMissing ( "wordForms" , "com.digitalpebble.rasp.Token" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Token_Type ) jcasType ) . casFeatCode_wordForms ) , i ) ; jcasType . ll_cas . ll_setRefArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Token_Type ) jcasType ) . casFeatCode_wordForms ) , i , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | indexed setter for wordForms - sets an indexed value - A Token is related to one or more WordForm |
20,908 | public boolean trainOnAll ( ) { List < Map < String , String > > trueLabels = loadLabels ( _trueLabelsFile ) ; List < String > corpus = loadTrainingCorpus ( _trainingCorpusFile ) ; List < List < Acronym > > trainingExtractedCandidates = new ArrayList < List < Acronym > > ( ) ; List < Map < String , String > > trueLabelsForTraining = new ArrayList < Map < String , String > > ( ) ; for ( Integer docID = 0 ; docID < corpus . size ( ) ; ++ docID ) { trainingExtractedCandidates . add ( extractCandidatePairs ( corpus . get ( docID ) ) ) ; trueLabelsForTraining . add ( trueLabels . get ( docID ) ) ; } return _abbvHmm . train ( trainingExtractedCandidates , trueLabelsForTraining , true ) ; } | Trains on full corpus |
20,909 | public boolean trainOnCandidates ( ) { List < String > corpus = loadTrainingCorpus ( _trainingCorpusFile ) ; List < List < Acronym > > trainingExtractedCandidates = new ArrayList < List < Acronym > > ( ) ; for ( Integer docID = 0 ; docID < corpus . size ( ) ; ++ docID ) { trainingExtractedCandidates . add ( extractCandidatePairs ( corpus . get ( docID ) ) ) ; } return _abbvHmm . train ( trainingExtractedCandidates , null , true ) ; } | Trains on candidate pairs extracted from the corpus |
20,910 | public String getBiolexicon_id ( ) { if ( POSVerb_Type . featOkTst && ( ( POSVerb_Type ) jcasType ) . casFeat_biolexicon_id == null ) jcasType . jcas . throwFeatMissing ( "biolexicon_id" , "ch.epfl.bbp.uima.types.POSVerb" ) ; return jcasType . ll_cas . ll_getStringValue ( addr , ( ( POSVerb_Type ) jcasType ) . casFeatCode_biolexicon_id ) ; } | getter for biolexicon_id - gets |
20,911 | public void setBiolexicon_id ( String v ) { if ( POSVerb_Type . featOkTst && ( ( POSVerb_Type ) jcasType ) . casFeat_biolexicon_id == null ) jcasType . jcas . throwFeatMissing ( "biolexicon_id" , "ch.epfl.bbp.uima.types.POSVerb" ) ; jcasType . ll_cas . ll_setStringValue ( addr , ( ( POSVerb_Type ) jcasType ) . casFeatCode_biolexicon_id , v ) ; } | setter for biolexicon_id - sets |
20,912 | public void setBody ( String body ) { String xbody = body ; String [ ] row = xbody . split ( "\n" ) ; for ( int i = 0 ; i < row . length ; i ++ ) { this . m_xbody . add ( row [ i ] ) ; } } | Sets the table body cells into an array |
20,913 | public void setHeading ( String heading ) { String m_heading = heading ; String [ ] preCol = m_heading . split ( "\n" ) ; String [ ] [ ] cells = new String [ preCol . length ] [ this . m_columnNumber ] ; for ( int i = 0 ; i < preCol . length ; i ++ ) cells [ i ] = preCol [ i ] . split ( ";" , this . m_columnNumber ) ; for ( int i = 0 ; i < cells [ 0 ] . length ; i ++ ) { String xhead = "" ; for ( int j = 0 ; j < preCol . length ; j ++ ) { xhead += ( cells [ j ] [ i ] + " " ) ; } this . m_xheading . add ( xhead ) ; } } | Sets the table heading rows |
20,914 | public void setValidTable ( TableCandidate tc ) { this . setHeight ( tc . getHeight ( ) ) ; this . setWidth ( tc . getWidth ( ) ) ; this . setCaption ( tc . getCaption ( ) ) ; this . setRowNumber ( tc . getRows ( ) . size ( ) ) ; this . setColumnNumber ( tc . getColumnNum_thisTable ( ) ) ; this . setRefTextList ( tc . getRefText ( ) ) ; this . setFootNote ( tc . getFootnoteText ( ) ) ; this . setHeading ( tc . getColumnHeadings ( ) ) ; this . setBody ( tc . getTableContent ( ) ) ; } | Sets the metadata of a valid table |
20,915 | public String getLexical_condition ( ) { if ( RelationMention_Type . featOkTst && ( ( RelationMention_Type ) jcasType ) . casFeat_lexical_condition == null ) jcasType . jcas . throwFeatMissing ( "lexical_condition" , "de.julielab.jules.types.ace.RelationMention" ) ; return jcasType . ll_cas . ll_getStringValue ( addr , ( ( RelationMention_Type ) jcasType ) . casFeatCode_lexical_condition ) ; } | getter for lexical_condition - gets |
20,916 | public void setLexical_condition ( String v ) { if ( RelationMention_Type . featOkTst && ( ( RelationMention_Type ) jcasType ) . casFeat_lexical_condition == null ) jcasType . jcas . throwFeatMissing ( "lexical_condition" , "de.julielab.jules.types.ace.RelationMention" ) ; jcasType . ll_cas . ll_setStringValue ( addr , ( ( RelationMention_Type ) jcasType ) . casFeatCode_lexical_condition , v ) ; } | setter for lexical_condition - sets |
20,917 | public Relation getRelation_ref ( ) { if ( RelationMention_Type . featOkTst && ( ( RelationMention_Type ) jcasType ) . casFeat_relation_ref == null ) jcasType . jcas . throwFeatMissing ( "relation_ref" , "de.julielab.jules.types.ace.RelationMention" ) ; return ( Relation ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( RelationMention_Type ) jcasType ) . casFeatCode_relation_ref ) ) ) ; } | getter for relation_ref - gets |
20,918 | public void setRelation_ref ( Relation v ) { if ( RelationMention_Type . featOkTst && ( ( RelationMention_Type ) jcasType ) . casFeat_relation_ref == null ) jcasType . jcas . throwFeatMissing ( "relation_ref" , "de.julielab.jules.types.ace.RelationMention" ) ; jcasType . ll_cas . ll_setRefValue ( addr , ( ( RelationMention_Type ) jcasType ) . casFeatCode_relation_ref , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | setter for relation_ref - sets |
20,919 | private void loadMappings ( ) { for ( int i = 0 ; i < mappings . length ; i ++ ) { String [ ] pair = mappings [ i ] . split ( ";" ) ; if ( pair . length < 2 ) { try { throw new AnnotatorConfigurationException ( ) ; } catch ( AnnotatorConfigurationException e ) { LOGGER . error ( "[OpenNLP Parser: ]" + e . getMessage ( ) ) ; e . printStackTrace ( ) ; } } else { String consTag = pair [ 0 ] ; String casTag = pair [ 1 ] ; mapTable . put ( consTag , casTag ) ; } } } | load mappings of constituent names |
20,920 | private void annotate ( Parse parse , JCas cas , Constituent parent ) throws SecurityException , IllegalArgumentException , ClassNotFoundException , NoSuchMethodException , InstantiationException , IllegalAccessException , InvocationTargetException { Constituent cons = null ; Span span = parse . getSpan ( ) ; String label = parse . getType ( ) ; String labelCat ; String [ ] funCatlabels = null ; if ( ! label . equals ( ParserME . TOK_NODE ) ) { int start = offsetMap . getMapping ( span . getStart ( ) ) ; int end = offsetMap . getMapping ( span . getEnd ( ) ) ; if ( fun == true && label . contains ( "-" ) ) { funCatlabels = label . split ( "-" ) ; labelCat = funCatlabels [ 0 ] ; } else labelCat = label ; String casLabel = mapTable . get ( labelCat ) ; if ( casLabel != null ) { cons = ( Constituent ) AnnotationTools . getAnnotationByClassName ( cas , tagSet ) ; cons . setBegin ( start ) ; cons . setEnd ( end ) ; cons . setComponentId ( COMPONENT_ID ) ; cons . setCat ( casLabel ) ; Class c = cons . getClass ( ) ; makeFunAnnotations ( cons , funCatlabels ) ; if ( parent != null ) cons . setParent ( parent ) ; cons . addToIndexes ( ) ; } Parse [ ] children = parse . getChildren ( ) ; for ( int i = 0 ; i < children . length ; i ++ ) { annotate ( children [ i ] , cas , cons ) ; } } } | provide annotations from Parse result to CAS object |
20,921 | private void makeFunAnnotations ( Constituent cons , String [ ] funCatLabels ) { if ( funCatLabels != null && funCatLabels . length > 1 ) { String labeltype ; for ( int i = 1 ; i < funCatLabels . length ; i ++ ) { labeltype = funTable . get ( funCatLabels [ i ] ) ; if ( labeltype != null ) { Class c = cons . getClass ( ) ; if ( labeltype . equals ( "formFuncDisc" ) ) { if ( c . equals ( GENIAConstituent . class ) ) ( ( GENIAConstituent ) cons ) . setFormFuncDisc ( funCatLabels [ i ] ) ; if ( c . equals ( PennBioIEConstituent . class ) ) ( ( PennBioIEConstituent ) cons ) . setFormFuncDisc ( funCatLabels [ i ] ) ; if ( c . equals ( PTBConstituent . class ) ) ( ( PTBConstituent ) cons ) . setFormFuncDisc ( funCatLabels [ i ] ) ; } if ( labeltype . equals ( "gramRole" ) ) { if ( c . equals ( GENIAConstituent . class ) ) ( ( GENIAConstituent ) cons ) . setGramRole ( funCatLabels [ i ] ) ; if ( c . equals ( PennBioIEConstituent . class ) ) ( ( PennBioIEConstituent ) cons ) . setGramRole ( funCatLabels [ i ] ) ; if ( c . equals ( PTBConstituent . class ) ) ( ( PTBConstituent ) cons ) . setGramRole ( funCatLabels [ i ] ) ; } if ( labeltype . equals ( "adv" ) ) { if ( c . equals ( GENIAConstituent . class ) ) ( ( GENIAConstituent ) cons ) . setAdv ( funCatLabels [ i ] ) ; if ( c . equals ( PennBioIEConstituent . class ) ) ( ( PennBioIEConstituent ) cons ) . setAdv ( funCatLabels [ i ] ) ; if ( c . equals ( PTBConstituent . class ) ) ( ( PTBConstituent ) cons ) . setAdv ( funCatLabels [ i ] ) ; } if ( labeltype . equals ( "misc" ) ) { if ( c . equals ( GENIAConstituent . class ) ) ( ( GENIAConstituent ) cons ) . setMisc ( funCatLabels [ i ] ) ; if ( c . equals ( PennBioIEConstituent . class ) ) ( ( PennBioIEConstituent ) cons ) . setMisc ( funCatLabels [ i ] ) ; if ( c . equals ( PTBConstituent . class ) ) ( ( PTBConstituent ) cons ) . setMisc ( funCatLabels [ i ] ) ; } if ( labeltype . equals ( "syn" ) ) { if ( c . equals ( GENIAConstituent . class ) ) ( ( GENIAConstituent ) cons ) . setSyn ( funCatLabels [ i ] ) ; } } } } } | make Fun annotations |
20,922 | private void initBracketMap ( ) { escMap . put ( "(" , "-LRB-" ) ; escMap . put ( ")" , "-RRB-" ) ; escMap . put ( "{" , "-LCB-" ) ; escMap . put ( "}" , "-RCB-" ) ; escMap . put ( "[" , "-LSB-" ) ; escMap . put ( "]" , "-RSB-" ) ; } | init table with charactets to be escaped |
20,923 | private void initFunMap ( ) { funTable . put ( "ADV" , "formFuncDisc" ) ; funTable . put ( "NOM" , "formFuncDisc" ) ; funTable . put ( "DTV" , "gramRole" ) ; funTable . put ( "LGS" , "gramRole" ) ; funTable . put ( "PRD" , "gramRole" ) ; funTable . put ( "PUT" , "gramRole" ) ; funTable . put ( "SBJ" , "gramRole" ) ; funTable . put ( "VOC" , "gramRole" ) ; funTable . put ( "BNF" , "adv" ) ; funTable . put ( "DIR" , "adv" ) ; funTable . put ( "EXT" , "adv" ) ; funTable . put ( "LOC" , "adv" ) ; funTable . put ( "MNR" , "adv" ) ; funTable . put ( "PRP" , "adv" ) ; funTable . put ( "TMP" , "adv" ) ; funTable . put ( "CLR" , "misc" ) ; funTable . put ( "CLF" , "misc" ) ; funTable . put ( "HLN" , "misc" ) ; funTable . put ( "TTL" , "misc" ) ; funTable . put ( "COOD" , "syn" ) ; } | init table wit fun tags and corresponfing attributes of a Constituent |
20,924 | private String [ ] getLoadline ( Pair < BrainRegion , BrainRegion > pair , int pmId ) { BrainRegion br1 = pair . getKey ( ) ; BrainRegion br2 = pair . getValue ( ) ; return new String [ ] { pmId + "" , br1 . getCoveredText ( ) . replaceAll ( "(\\r|\\n|\\t)" , "" ) , br1 . getBegin ( ) + "" , br1 . getEnd ( ) + "" , br2 . getCoveredText ( ) . replaceAll ( "(\\r|\\n|\\t)" , "" ) , br2 . getBegin ( ) + "" , br2 . getEnd ( ) + "" } ; } | pubmed_id region_1_name region_1_start region_1_end region_2_name region_2_start region_2_end |
20,925 | public void eval ( int [ ] context , double [ ] outsums ) { for ( int oid = 0 ; oid < numOutcomes ; oid ++ ) { outsums [ oid ] = iprob ; numfeats [ oid ] = 0 ; } int [ ] activeOutcomes ; double [ ] activeParameters ; for ( int i = 0 ; i < context . length ; i ++ ) { Context predParams = params [ context [ i ] ] ; activeOutcomes = predParams . getOutcomes ( ) ; activeParameters = predParams . getParameters ( ) ; for ( int j = 0 ; j < activeOutcomes . length ; j ++ ) { int oid = activeOutcomes [ j ] ; numfeats [ oid ] ++ ; outsums [ oid ] += constantInverse * activeParameters [ j ] ; } } double SUM = 0.0 ; for ( int oid = 0 ; oid < numOutcomes ; oid ++ ) { outsums [ oid ] = Math . exp ( outsums [ oid ] ) ; if ( _useSlackParameter ) { outsums [ oid ] += ( ( 1.0 - ( ( double ) numfeats [ oid ] / constant ) ) * correctionParam ) ; } SUM += outsums [ oid ] ; } for ( int oid = 0 ; oid < numOutcomes ; oid ++ ) outsums [ oid ] /= SUM ; } | Use this model to evaluate a context and populate the specified outsums array with the likelihood of each outcome given that context . |
20,926 | public boolean getHasBold ( ) { if ( DocumentBlock_Type . featOkTst && ( ( DocumentBlock_Type ) jcasType ) . casFeat_hasBold == null ) jcasType . jcas . throwFeatMissing ( "hasBold" , "ch.epfl.bbp.uima.types.DocumentBlock" ) ; return jcasType . ll_cas . ll_getBooleanValue ( addr , ( ( DocumentBlock_Type ) jcasType ) . casFeatCode_hasBold ) ; } | getter for hasBold - gets |
20,927 | public void setHasBold ( boolean v ) { if ( DocumentBlock_Type . featOkTst && ( ( DocumentBlock_Type ) jcasType ) . casFeat_hasBold == null ) jcasType . jcas . throwFeatMissing ( "hasBold" , "ch.epfl.bbp.uima.types.DocumentBlock" ) ; jcasType . ll_cas . ll_setBooleanValue ( addr , ( ( DocumentBlock_Type ) jcasType ) . casFeatCode_hasBold , v ) ; } | setter for hasBold - sets |
20,928 | public boolean getHasManyFontsizes ( ) { if ( DocumentBlock_Type . featOkTst && ( ( DocumentBlock_Type ) jcasType ) . casFeat_hasManyFontsizes == null ) jcasType . jcas . throwFeatMissing ( "hasManyFontsizes" , "ch.epfl.bbp.uima.types.DocumentBlock" ) ; return jcasType . ll_cas . ll_getBooleanValue ( addr , ( ( DocumentBlock_Type ) jcasType ) . casFeatCode_hasManyFontsizes ) ; } | getter for hasManyFontsizes - gets |
20,929 | public void setHasManyFontsizes ( boolean v ) { if ( DocumentBlock_Type . featOkTst && ( ( DocumentBlock_Type ) jcasType ) . casFeat_hasManyFontsizes == null ) jcasType . jcas . throwFeatMissing ( "hasManyFontsizes" , "ch.epfl.bbp.uima.types.DocumentBlock" ) ; jcasType . ll_cas . ll_setBooleanValue ( addr , ( ( DocumentBlock_Type ) jcasType ) . casFeatCode_hasManyFontsizes , v ) ; } | setter for hasManyFontsizes - sets |
20,930 | public java . util . List < Object > getAppOrRefList ( ) { if ( appOrRefList == null ) { appOrRefList = new ArrayList < Object > ( ) ; } return this . appOrRefList ; } | Gets the value of the appOrRefList property . |
20,931 | private static String getHelp ( ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( "\njSRE: Simple Relation Extraction V1.10\t 30.08.06\n" ) ; sb . append ( "developed by Claudio Giuliano (giuliano@itc.it)\n\n" ) ; sb . append ( "Copyright 2005 FBK-irst (http://www.fbk.eu)\n" ) ; sb . append ( "\n" ) ; sb . append ( "Licensed under the Apache License, Version 2.0 (the \"License\");\n" ) ; sb . append ( "you may not use this file except in compliance with the License.\n" ) ; sb . append ( "You may obtain a copy of the License at\n" ) ; sb . append ( "\n" ) ; sb . append ( " http://www.apache.org/licenses/LICENSE-2.0\n" ) ; sb . append ( "\n" ) ; sb . append ( "Unless required by applicable law or agreed to in writing, software\n" ) ; sb . append ( "distributed under the License is distributed on an \"AS IS\" BASIS,\n" ) ; sb . append ( "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" ) ; sb . append ( "See the License for the specific language governing permissions and\n" ) ; sb . append ( "limitations under the License.\n\n" ) ; sb . append ( "Usage: java org.itc.irst.tcc.sre.SentenceSet2VectorSet [options] example-file model-file output-file\n\n" ) ; sb . append ( "Arguments:\n" ) ; sb . append ( "\ttest-file\t-> file with test data (SRE format)\n" ) ; sb . append ( "\tmodel-file\t-> file from which to load the learned model\n" ) ; sb . append ( "\toutput-file\t-> file in which to store resulting output\n" ) ; sb . append ( "Options:\n" ) ; sb . append ( "\t-h\t\t-> this help\n" ) ; return sb . toString ( ) ; } | Returns a command - line help . |
20,932 | public void clear ( String what ) { if ( what . equals ( "blockers" ) ) blockers . clear ( ) ; else if ( what . equals ( "datasets" ) ) datasets . clear ( ) ; else if ( what . equals ( "learners" ) ) learners . clear ( ) ; else if ( what . equals ( "all" ) ) { clear ( "blockers" ) ; clear ( "datasets" ) ; clear ( "learners" ) ; } else { System . out . println ( "usage: clear blockers|datasets|learners|all" ) ; } } | Clear datasets blockers or learners . |
20,933 | public void show ( String what ) { if ( what . equals ( "blockers" ) ) showList ( "blockers" , blockerNames ) ; else if ( what . equals ( "datasets" ) ) showList ( "datasets" , datasetNames ) ; else if ( what . equals ( "learners" ) ) showList ( "learners" , learnerNames ) ; else if ( what . equals ( "all" ) ) { show ( "blockers" ) ; show ( "datasets" ) ; show ( "learners" ) ; } else { System . out . println ( "usage: show blockers|datasets|learners|all" ) ; } } | Show datasets blockers or learners . |
20,934 | public void dataset ( String dataFile ) throws MatchData . InputFormatException { datasets . add ( new MatchData ( dataFile ) ) ; datasetNames . add ( dataFile ) ; expt = null ; } | Load a dataset . |
20,935 | public void learner ( String learnerClass ) { learners . add ( DistanceLearnerFactory . build ( learnerClass ) ) ; learnerNames . add ( learnerClass ) ; expt = null ; } | Load a learner . |
20,936 | public void blocker ( String blockerClass ) throws ClassNotFoundException , InstantiationException , IllegalAccessException { blockers . add ( Class . forName ( BLOCKER_PACKAGE + blockerClass ) . newInstance ( ) ) ; blockerNames . add ( blockerClass ) ; expt = null ; } | Load a blocker . |
20,937 | public void blocker ( String blockerClass , String param , String value ) throws ClassNotFoundException , InstantiationException , IllegalAccessException , InvocationTargetException , NoSuchMethodException { Blocker blocker = ( Blocker ) Class . forName ( BLOCKER_PACKAGE + blockerClass ) . newInstance ( ) ; param = param . substring ( 0 , 1 ) . toUpperCase ( ) + param . substring ( 1 , param . length ( ) ) ; Method m = blocker . getClass ( ) . getMethod ( "set" + param , new Class [ ] { Boolean . class } ) ; m . invoke ( blocker , new Object [ ] { Boolean . valueOf ( value ) } ) ; blockers . add ( blocker ) ; blockerNames . add ( blockerClass ) ; expt = null ; } | Load a blocker with optional boolean value |
20,938 | public void compute ( ) { if ( ! computable ) { throw new RuntimeException ( "can't re-'compute' experiment results after a 'restore'" ) ; } expt = new MatchExpt [ blockers . size ( ) ] [ learners . size ( ) ] [ datasets . size ( ) ] ; for ( int i = 0 ; i < blockers . size ( ) ; i ++ ) { Blocker blocker = ( Blocker ) blockers . get ( i ) ; for ( int j = 0 ; j < learners . size ( ) ; j ++ ) { StringDistanceLearner distance = ( StringDistanceLearner ) learners . get ( j ) ; for ( int k = 0 ; k < datasets . size ( ) ; k ++ ) { MatchData dataset = ( MatchData ) datasets . get ( k ) ; expt [ i ] [ j ] [ k ] = new MatchExpt ( dataset , distance , blocker ) ; } } } } | Compute learners . |
20,939 | public void table ( String what ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { PrintfFormat dfmt = new PrintfFormat ( "Dataset %2d:" ) ; PrintfFormat fmt = new PrintfFormat ( " %9.5f " ) ; PrintfFormat nfmt = new PrintfFormat ( " %11s" ) ; if ( expt == null ) compute ( ) ; for ( int i = 0 ; i < blockerNames . size ( ) ; i ++ ) { System . out . println ( "\nblocker: " + blockerNames . get ( i ) + "\n" ) ; System . out . print ( " " ) ; for ( int j = 0 ; j < learnerNames . size ( ) ; j ++ ) { String s = ( String ) learnerNames . get ( j ) ; if ( s . length ( ) > 11 ) s = s . substring ( 0 , 11 ) ; System . out . print ( nfmt . sprintf ( s ) ) ; } System . out . println ( ) ; double [ ] average = new double [ learnerNames . size ( ) ] ; for ( int k = 0 ; k < datasetNames . size ( ) ; k ++ ) { System . out . print ( dfmt . sprintf ( k + 1 ) ) ; for ( int j = 0 ; j < learnerNames . size ( ) ; j ++ ) { Method m = MatchExpt . class . getMethod ( what , new Class [ ] { } ) ; Double d = ( Double ) m . invoke ( expt [ i ] [ j ] [ k ] , new Object [ ] { } ) ; System . out . print ( fmt . sprintf ( d ) ) ; average [ j ] += d . doubleValue ( ) ; } System . out . print ( "\n" ) ; } System . out . print ( " Average:" ) ; for ( int j = 0 ; j < learnerNames . size ( ) ; j ++ ) { System . out . print ( fmt . sprintf ( average [ j ] / datasetNames . size ( ) ) ) ; } System . out . print ( "\n\n" ) ; } } | Show a table of some expt - wide numeric measurement . |
20,940 | public void save ( String file ) throws IOException , FileNotFoundException { ObjectOutputStream oos = new ObjectOutputStream ( new FileOutputStream ( file ) ) ; oos . writeObject ( blockerNames ) ; oos . writeObject ( datasetNames ) ; oos . writeObject ( learnerNames ) ; oos . writeObject ( expt ) ; oos . close ( ) ; } | Save current experimental data to a file |
20,941 | public void restore ( String file ) throws IOException , FileNotFoundException , ClassNotFoundException { ObjectInputStream ois = new ObjectInputStream ( new FileInputStream ( file ) ) ; blockerNames = ( List ) ois . readObject ( ) ; datasetNames = ( List ) ois . readObject ( ) ; learnerNames = ( List ) ois . readObject ( ) ; expt = ( MatchExpt [ ] [ ] [ ] ) ois . readObject ( ) ; computable = false ; ois . close ( ) ; } | Restore experimental data previously saved toa file . It will be possible to analyze this data with table commands and etc but not to perform additional experiments . |
20,942 | public void runScript ( String configFileName ) { int lineNum = 0 ; try { BufferedReader in = new BufferedReader ( new FileReader ( configFileName ) ) ; String line ; while ( ( line = in . readLine ( ) ) != null ) { lineNum ++ ; if ( ! line . startsWith ( "#" ) ) { String command = null ; List args = new ArrayList ( ) ; StringTokenizer tok = new StringTokenizer ( line ) ; if ( tok . hasMoreTokens ( ) ) { command = tok . nextToken ( ) ; } while ( tok . hasMoreTokens ( ) ) { args . add ( tok . nextToken ( ) ) ; } if ( command != null ) { if ( echoCommands ) System . out . println ( "exec: " + line ) ; execCommand ( command , args ) ; } } } } catch ( Exception e ) { System . out . println ( "Error: " + configFileName + " line " + lineNum + ": " + e . toString ( ) ) ; e . printStackTrace ( ) ; return ; } } | Load commands from a file and execute them . |
20,943 | private void execCommand ( String command , List args ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { Class [ ] template = new Class [ args . size ( ) ] ; for ( int i = 0 ; i < args . size ( ) ; i ++ ) { template [ i ] = String . class ; } Method m = MatchExptScript . class . getMethod ( command , template ) ; m . invoke ( this , args . toArray ( new String [ 0 ] ) ) ; } | execute a single command |
20,944 | public StringWrapper prepare ( String s ) { BagOfTokens bag = new BagOfTokens ( s , tokenizer . tokenize ( s ) ) ; double normalizer = 0.0 ; for ( Iterator i = bag . tokenIterator ( ) ; i . hasNext ( ) ; ) { Token tok = ( Token ) i . next ( ) ; if ( collectionSize > 0 ) { Integer dfInteger = ( Integer ) documentFrequency . get ( tok ) ; double df = dfInteger == null ? 1.0 : dfInteger . intValue ( ) ; double w = - Math . log ( df / collectionSize ) ; bag . setWeight ( tok , w ) ; } else { bag . setWeight ( tok , Math . log ( 10 ) ) ; } } return bag ; } | Preprocess a string by finding tokens and giving them appropriate weights |
20,945 | public static String format ( String msg , Object ... args ) { if ( args == null || args . length == 0 ) return msg ; StringBuilder sb = new StringBuilder ( ) ; int argId = 0 ; for ( int i = 0 ; i < msg . length ( ) ; i ++ ) { final char c = msg . charAt ( i ) ; if ( c == '{' && msg . charAt ( i + 1 ) == '}' ) { if ( args . length > argId ) { Object val = args [ argId ++ ] ; if ( val == null ) sb . append ( "null" ) ; else sb . append ( val . toString ( ) ) ; } else { sb . append ( "{{MISSING ARG}}" ) ; } i ++ ; } else { sb . append ( c ) ; } } return sb . toString ( ) ; } | Similar to Slf4J logger |
20,946 | public Token [ ] tokenize ( String input ) { Token [ ] initialTokens = innerTokenizer . tokenize ( input ) ; List tokens = new ArrayList ( ) ; for ( int i = 0 ; i < initialTokens . length ; i ++ ) { Token tok = initialTokens [ i ] ; String str = "^" + tok . getValue ( ) + "$" ; if ( keepOldTokens ) tokens . add ( intern ( str ) ) ; for ( int lo = 0 ; lo < str . length ( ) ; lo ++ ) { for ( int len = minNGramSize ; len <= maxNGramSize ; len ++ ) { if ( lo + len < str . length ( ) ) { tokens . add ( innerTokenizer . intern ( str . substring ( lo , lo + len ) ) ) ; } } } } return ( Token [ ] ) tokens . toArray ( new BasicToken [ tokens . size ( ) ] ) ; } | Return tokenized version of a string . Tokens are all character n - grams that are part of a token produced by the inner tokenizer . |
20,947 | public FSArray getCategories ( ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_categories == null ) jcasType . jcas . throwFeatMissing ( "categories" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; return ( FSArray ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_categories ) ) ) ; } | getter for categories - gets List of Wikipedia categories associated with a Wikipedia page . |
20,948 | public void setCategories ( FSArray v ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_categories == null ) jcasType . jcas . throwFeatMissing ( "categories" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . ll_cas . ll_setRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_categories , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | setter for categories - sets List of Wikipedia categories associated with a Wikipedia page . |
20,949 | public Title getCategories ( int i ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_categories == null ) jcasType . jcas . throwFeatMissing ( "categories" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_categories ) , i ) ; return ( Title ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_categories ) , i ) ) ) ; } | indexed getter for categories - gets an indexed value - List of Wikipedia categories associated with a Wikipedia page . |
20,950 | public void setCategories ( int i , Title v ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_categories == null ) jcasType . jcas . throwFeatMissing ( "categories" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_categories ) , i ) ; jcasType . ll_cas . ll_setRefArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_categories ) , i , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | indexed setter for categories - sets an indexed value - List of Wikipedia categories associated with a Wikipedia page . |
20,951 | public FSArray getOutgoingLinks ( ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_outgoingLinks == null ) jcasType . jcas . throwFeatMissing ( "outgoingLinks" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; return ( FSArray ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_outgoingLinks ) ) ) ; } | getter for outgoingLinks - gets List of outgoing links pointing to other Wikipedia pages starting at a Wikipedia page . |
20,952 | public void setOutgoingLinks ( FSArray v ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_outgoingLinks == null ) jcasType . jcas . throwFeatMissing ( "outgoingLinks" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . ll_cas . ll_setRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_outgoingLinks , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | setter for outgoingLinks - sets List of outgoing links pointing to other Wikipedia pages starting at a Wikipedia page . |
20,953 | public Title getOutgoingLinks ( int i ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_outgoingLinks == null ) jcasType . jcas . throwFeatMissing ( "outgoingLinks" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_outgoingLinks ) , i ) ; return ( Title ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_outgoingLinks ) , i ) ) ) ; } | indexed getter for outgoingLinks - gets an indexed value - List of outgoing links pointing to other Wikipedia pages starting at a Wikipedia page . |
20,954 | public void setOutgoingLinks ( int i , Title v ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_outgoingLinks == null ) jcasType . jcas . throwFeatMissing ( "outgoingLinks" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_outgoingLinks ) , i ) ; jcasType . ll_cas . ll_setRefArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_outgoingLinks ) , i , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | indexed setter for outgoingLinks - sets an indexed value - List of outgoing links pointing to other Wikipedia pages starting at a Wikipedia page . |
20,955 | public StringArray getRedirects ( ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_redirects == null ) jcasType . jcas . throwFeatMissing ( "redirects" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; return ( StringArray ) ( jcasType . ll_cas . ll_getFSForRef ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_redirects ) ) ) ; } | getter for redirects - gets List of redirects pointing to a Wikipedia page . |
20,956 | public void setRedirects ( StringArray v ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_redirects == null ) jcasType . jcas . throwFeatMissing ( "redirects" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . ll_cas . ll_setRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_redirects , jcasType . ll_cas . ll_getFSRef ( v ) ) ; } | setter for redirects - sets List of redirects pointing to a Wikipedia page . |
20,957 | public String getRedirects ( int i ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_redirects == null ) jcasType . jcas . throwFeatMissing ( "redirects" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_redirects ) , i ) ; return jcasType . ll_cas . ll_getStringArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_redirects ) , i ) ; } | indexed getter for redirects - gets an indexed value - List of redirects pointing to a Wikipedia page . |
20,958 | public void setRedirects ( int i , String v ) { if ( Descriptor_Type . featOkTst && ( ( Descriptor_Type ) jcasType ) . casFeat_redirects == null ) jcasType . jcas . throwFeatMissing ( "redirects" , "de.julielab.jules.types.wikipedia.Descriptor" ) ; jcasType . jcas . checkArrayBounds ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_redirects ) , i ) ; jcasType . ll_cas . ll_setStringArrayValue ( jcasType . ll_cas . ll_getRefValue ( addr , ( ( Descriptor_Type ) jcasType ) . casFeatCode_redirects ) , i , v ) ; } | indexed setter for redirects - sets an indexed value - List of redirects pointing to a Wikipedia page . |
20,959 | public java . util . List < Object > getRid ( ) { if ( rid == null ) { rid = new ArrayList < Object > ( ) ; } return this . rid ; } | Gets the value of the rid property . |
20,960 | public static Pipeline parse ( File scriptFile , List < String > replacementVars ) throws ParseException , IOException { checkArgument ( scriptFile . exists ( ) , "could not find pipeline script file at " + scriptFile . getAbsolutePath ( ) ) ; return parse ( FileUtils . readLines ( scriptFile ) , scriptFile . getParent ( ) , replacementVars ) ; } | Parses a pipeline script file . |
20,961 | public static Pipeline parse ( List < String > scriptLines , String parentFilePath , List < String > replacementVars ) throws ParseException , IOException { if ( replacementVars == null ) replacementVars = new ArrayList < String > ( ) ; Pipeline pipeline = parseAndDispatch ( scriptLines , new Pipeline ( ) , parentFilePath , replacementVars ) ; if ( pipeline . crd == null ) LOG . warn ( "no CollectionReader defined in this pipeline" ) ; if ( pipeline . aeds . isEmpty ( ) ) throw new ParseException ( "no analysis engines defined in this pipeline script, at least define one" , - 1 ) ; return pipeline ; } | Parses lines from a pipeline script . |
20,962 | private static void parsePython ( IteratorWithPrevious < String > it , Pipeline pipeline ) throws ParseException { String script = "" ; while ( it . hasNext ( ) ) { String current = it . next ( ) ; if ( StringUtils . isBlank ( current ) ) break ; script += current + "\n" ; } if ( script . length ( ) < 3 ) throw new ParseException ( "empty script" , - 1 ) ; try { AnalysisEngineDescription aed = AnalysisEngineFactory . createEngineDescription ( JythonAnnotator2 . class , JythonAnnotator2 . SCRIPT_STRING , script ) ; pipeline . addAe ( aed ) ; } catch ( ResourceInitializationException e ) { throw new ParseException ( "could not create aed with script, " + e . getMessage ( ) , - 1 ) ; } } | Parses inline raw Python code and executes it with Jython |
20,963 | private static void parseJava ( IteratorWithPrevious < String > it , Pipeline pipeline ) throws ParseException { String script = "" ; while ( it . hasNext ( ) ) { String current = it . next ( ) ; if ( isBlank ( current ) ) break ; script += current + "\n" ; } if ( script . length ( ) < 3 ) throw new ParseException ( "empty script" , - 1 ) ; try { pipeline . aeds . add ( createEngineDescription ( BeanshellAnnotator . class , SCRIPT_STRING , script ) ) ; } catch ( ResourceInitializationException e ) { throw new ParseException ( "could not create aed with script " + script , - 1 ) ; } } | Parses inline raw java code and executes it with Beanshell |
20,964 | private static void parseInclude ( String line , Pipeline pipeline , String parentFilePath , List < String > cliArgs ) throws ParseException { LOG . info ( "+-parsing include line '{}'" , line ) ; String includeName = line . replaceFirst ( "include: " , "" ) . trim ( ) ; File includeFile = null ; if ( includeName . startsWith ( "/" ) ) { includeFile = new File ( includeName ) ; } else { includeFile = new File ( parentFilePath , includeName ) ; } if ( ! includeFile . exists ( ) ) { String didYouMean = "" ; if ( new File ( parentFilePath , "../" + includeName ) . exists ( ) ) { didYouMean = "\ndid you mean: '../" + includeName + "'" ; } else if ( new File ( parentFilePath , includeName . replaceFirst ( "\\.\\./" , "" ) ) . exists ( ) ) { didYouMean = "\ndid you mean: '" + includeName . replaceFirst ( "\\.\\./" , "" ) + "'" ; } throw new ParseException ( "include file does not exist (" + includeFile . getAbsolutePath ( ) + ") " + didYouMean , - 1 ) ; } try { List < String > includeStr = FileUtils . readLines ( includeFile ) ; includeStr . add ( "" ) ; includeStr . add ( "" ) ; parseAndDispatch ( includeStr , pipeline , includeFile . getParentFile ( ) . getAbsolutePath ( ) , cliArgs ) ; } catch ( IOException e ) { throw new ParseException ( "cannot read include file (" + includeFile . getAbsolutePath ( ) + ")" , - 1 ) ; } } | parse include commands |
20,965 | private static void validateParams ( List < Object > params , Class < ? > classz ) { if ( ! JCasAnnotator_ImplBase . class . isAssignableFrom ( classz ) && ! JCasCollectionReader_ImplBase . class . isAssignableFrom ( classz ) ) { LOG . warn ( " +- Could not validate parameters in {}. You might want to check it manually." , classz . getName ( ) ) ; return ; } for ( int i = 0 ; i < params . size ( ) ; i = i + 2 ) { String paramName = ( String ) params . get ( i ) ; try { Set < Field > fields = newHashSet ( classz . getDeclaredFields ( ) ) ; fields . addAll ( newHashSet ( classz . getSuperclass ( ) . getDeclaredFields ( ) ) ) ; List < String > paramNames = new ArrayList < String > ( ) ; for ( Field f : fields ) { if ( f . isAnnotationPresent ( ConfigurationParameter . class ) ) { ConfigurationParameter confParam = f . getAnnotation ( ConfigurationParameter . class ) ; paramNames . add ( confParam . name ( ) ) ; } } if ( ! paramNames . contains ( paramName ) ) { LOG . warn ( " +-XXXXXXXXX Could not find parameter '{}' in {}. You should check it." , paramName , classz . getName ( ) ) ; LOG . warn ( " +-XXXXXXXXX Available parameters are:\n" , join ( paramNames , "\n" ) ) ; } } catch ( SecurityException e ) { LOG . error ( "could not validate params for " + classz . getSimpleName ( ) , e ) ; } } } | check that this ae or cr has the right parameters |
20,966 | protected static String debugText ( String heading , Authentication auth , Collection < ConfigAttribute > config , Object resource , int decision ) { StringBuilder sb = new StringBuilder ( heading ) ; sb . append ( ": " ) ; if ( auth != null ) { sb . append ( auth . getName ( ) ) ; } if ( config != null ) { Collection < ConfigAttribute > atts = config ; if ( atts != null && atts . size ( ) > 0 ) { sb . append ( " [" ) ; for ( ConfigAttribute att : atts ) { sb . append ( att . getAttribute ( ) ) ; sb . append ( "," ) ; } sb . replace ( sb . length ( ) - 1 , sb . length ( ) , "]" ) ; } } if ( resource != null ) { sb . append ( " resource: [" ) ; sb . append ( resource . toString ( ) ) ; sb . append ( "]" ) ; } sb . append ( " => decision: " + decision ) ; return sb . toString ( ) ; } | This is small debug utility available to voters in this package . |
20,967 | public S3TaskClient get ( String storeId ) throws ContentStoreException { ContentStore contentStore = contentStoreManager . getContentStore ( storeId ) ; return new S3TaskClientImpl ( contentStore ) ; } | Retrieve an S3TaskClient |
20,968 | public static void addFileToZipOutputStream ( File file , ZipOutputStream zipOs ) throws IOException { String fileName = file . getName ( ) ; try ( FileInputStream fos = new FileInputStream ( file ) ) { ZipEntry zipEntry = new ZipEntry ( fileName ) ; zipEntry . setSize ( file . length ( ) ) ; zipEntry . setTime ( System . currentTimeMillis ( ) ) ; zipOs . putNextEntry ( zipEntry ) ; byte [ ] buf = new byte [ 1024 ] ; int bytesRead ; while ( ( bytesRead = fos . read ( buf ) ) > 0 ) { zipOs . write ( buf , 0 , bytesRead ) ; } zipOs . closeEntry ( ) ; fos . close ( ) ; } } | Adds the specified file to the zip output stream . |
20,969 | private void checkStorageState ( StorageException e ) { if ( e . getCause ( ) instanceof AmazonS3Exception ) { String errorCode = ( ( AmazonS3Exception ) e . getCause ( ) ) . getErrorCode ( ) ; if ( INVALID_OBJECT_STATE . equals ( errorCode ) ) { String message = "The storage state of this content item " + "does not allow for this action to be taken. To resolve " + "this issue: 1. Request that this content item be " + "retrieved from offline storage 2. Wait (retrieval may " + "take up to 5 hours) 3. Retry this request" ; throw new StorageStateException ( message , e ) ; } } } | Recognize and handle exceptions due to content which resides in Glacier but has not been retrieved for access . |
20,970 | private URI generateAsynchronously ( String account , String spaceId , String storeId , String format ) throws Exception { StorageProviderType providerType = getStorageProviderType ( storeId ) ; InputStream manifest = manifestResource . getManifest ( account , storeId , spaceId , format ) ; String contentId = MessageFormat . format ( "generated-manifests/manifest-{0}_{1}_{2}.txt{3}" , spaceId , providerType . name ( ) . toLowerCase ( ) , DateUtil . convertToString ( System . currentTimeMillis ( ) , DateFormat . PLAIN_FORMAT ) , ".gz" ) ; String adminSpace = "x-duracloud-admin" ; URI uri = buildURI ( adminSpace , contentId ) ; StorageProvider provider = storageProviderFactory . getStorageProvider ( ) ; executor . execute ( ( ) -> { try { boolean gzip = true ; File file = IOUtil . writeStreamToFile ( manifest , gzip ) ; uploadManifestToDefaultStorageProvider ( format , adminSpace , contentId , file , provider , gzip ) ; } catch ( Exception ex ) { log . error ( "failed to generate manifest for space: spaceId=" + spaceId + ", storeId=" + storeId + " : " + ex . getMessage ( ) , ex ) ; } } ) ; return uri ; } | Generates a manifest file asynchronously and uploads to DuraCloud |
20,971 | public List < StorageAccount > getStorageAccounts ( ) { List < StorageAccount > accts = new ArrayList < > ( ) ; Iterator < String > ids = getAccountManager ( ) . getStorageAccountIds ( ) ; while ( ids . hasNext ( ) ) { accts . add ( getAccountManager ( ) . getStorageAccount ( ids . next ( ) ) ) ; } return accts ; } | This method returns all of the registered storage accounts . |
20,972 | public StorageProvider getStorageProvider ( String storageAccountId ) throws StorageException { storageAccountId = checkStorageAccountId ( storageAccountId ) ; if ( storageProviders . containsKey ( storageAccountId ) ) { return storageProviders . get ( storageAccountId ) ; } StorageAccountManager storageAccountManager = getAccountManager ( ) ; StorageAccount account = storageAccountManager . getStorageAccount ( storageAccountId ) ; if ( account == null ) { throw new NotFoundException ( "No store exists with ID " + storageAccountId ) ; } String username = account . getUsername ( ) ; String password = account . getPassword ( ) ; StorageProviderType type = account . getType ( ) ; StorageProvider storageProvider = null ; if ( type . equals ( StorageProviderType . AMAZON_S3 ) ) { storageProvider = new S3StorageProvider ( username , password , account . getOptions ( ) ) ; } else if ( type . equals ( StorageProviderType . AMAZON_GLACIER ) ) { storageProvider = new GlacierStorageProvider ( username , password , account . getOptions ( ) ) ; } else if ( type . equals ( StorageProviderType . IRODS ) ) { storageProvider = new IrodsStorageProvider ( username , password , account . getOptions ( ) ) ; } else if ( type . equals ( StorageProviderType . CHRONOPOLIS ) ) { storageProvider = new ChronopolisStorageProvider ( username , password ) ; } else if ( type . equals ( StorageProviderType . TEST_RETRY ) ) { storageProvider = new MockRetryStorageProvider ( ) ; } else if ( type . equals ( StorageProviderType . TEST_VERIFY_CREATE ) ) { storageProvider = new MockVerifyCreateStorageProvider ( ) ; } else if ( type . equals ( StorageProviderType . TEST_VERIFY_DELETE ) ) { storageProvider = new MockVerifyDeleteStorageProvider ( ) ; } else { throw new StorageException ( "Unsupported storage provider type (" + type . name ( ) + ") associated with storage account (" + storageAccountId + "): unable to create" ) ; } StorageProvider auditProvider = new AuditStorageProvider ( storageProvider , storageAccountManager . getAccountName ( ) , storageAccountId , type . getName ( ) , userUtil , auditQueue ) ; if ( storageProvider instanceof StorageProviderBase ) { ( ( StorageProviderBase ) storageProvider ) . setWrappedStorageProvider ( auditProvider ) ; } StorageProvider aclProvider = new ACLStorageProvider ( auditProvider , notifier , contextUtil ) ; StorageProvider brokeredProvider = new BrokeredStorageProvider ( statelessProvider , aclProvider , type , storageAccountId ) ; storageProviders . put ( storageAccountId , brokeredProvider ) ; return brokeredProvider ; } | Retrieves a particular storage provider based on the storage account ID . If no storage ID is provided use the primary storage provider account If no storage account can be found with the given ID throw NotFoundException |
20,973 | public void expireStorageProvider ( String storageAccountId ) { storageAccountId = checkStorageAccountId ( storageAccountId ) ; log . info ( "Expiring storage provider connection! Storage account id: {}" , storageAccountId ) ; storageProviders . remove ( storageAccountId ) ; } | Removes a particular storage provider from the cache which will require that the connection be recreated on the next call . |
20,974 | public void initialize ( DuraStoreInitConfig initConfig , String instanceHost , String instancePort , String accountId ) throws StorageException { this . initConfig = initConfig ; storageAccountManager . initialize ( initConfig . getStorageAccounts ( ) ) ; storageAccountManager . setEnvironment ( instanceHost , instancePort , accountId ) ; } | Initializes DuraStore with account information necessary to connect to Storage Providers . |
20,975 | public int getAttempts ( ) { String attempts = this . properties . get ( "attempts" ) ; if ( attempts == null ) { attempts = "0" ; } return Integer . parseInt ( attempts ) ; } | The number of completed attempts to process this task . |
20,976 | public String performTask ( String taskParameters ) { GetSignedCookiesUrlTaskParameters taskParams = GetSignedCookiesUrlTaskParameters . deserialize ( taskParameters ) ; String spaceId = taskParams . getSpaceId ( ) ; String ipAddress = taskParams . getIpAddress ( ) ; int minutesToExpire = taskParams . getMinutesToExpire ( ) ; if ( minutesToExpire <= 0 ) { minutesToExpire = DEFAULT_MINUTES_TO_EXPIRE ; } String redirectUrl = taskParams . getRedirectUrl ( ) ; log . info ( "Performing " + TASK_NAME + " task with parameters: spaceId=" + spaceId + ", minutesToExpire=" + minutesToExpire + ", ipAddress=" + ipAddress + ", redirectUrl=" + redirectUrl ) ; String bucketName = unwrappedS3Provider . getBucketName ( spaceId ) ; checkThatStreamingServiceIsEnabled ( spaceId , TASK_NAME ) ; DistributionSummary existingDist = getExistingDistribution ( bucketName ) ; if ( null == existingDist ) { throw new UnsupportedTaskException ( TASK_NAME , "The " + TASK_NAME + " task can only be used after a space " + "has been configured to enable secure streaming. Use " + StorageTaskConstants . ENABLE_STREAMING_TASK_NAME + " to enable secure streaming on this space." ) ; } String domainName = existingDist . getDomainName ( ) ; Calendar expireCalendar = Calendar . getInstance ( ) ; expireCalendar . add ( Calendar . MINUTE , minutesToExpire ) ; Map < String , String > signedCookies = new HashMap < > ( ) ; try { File cfKeyPathFile = getCfKeyPathFile ( this . cfKeyPath ) ; CloudFrontCookieSigner . CookiesForCustomPolicy cookies = CloudFrontCookieSigner . getCookiesForCustomPolicy ( SignerUtils . Protocol . https , domainName , cfKeyPathFile , "*" , cfKeyId , expireCalendar . getTime ( ) , null , ipAddress ) ; signedCookies . put ( cookies . getPolicy ( ) . getKey ( ) , cookies . getPolicy ( ) . getValue ( ) ) ; signedCookies . put ( cookies . getSignature ( ) . getKey ( ) , cookies . getSignature ( ) . getValue ( ) ) ; signedCookies . put ( cookies . getKeyPairId ( ) . getKey ( ) , cookies . getKeyPairId ( ) . getValue ( ) ) ; } catch ( InvalidKeySpecException | IOException e ) { throw new RuntimeException ( "Error encountered attempting to create signed cookies in task " + TASK_NAME + ": " + e . getMessage ( ) , e ) ; } String token = storeCookies ( signedCookies , domainName , redirectUrl ) ; GetSignedCookiesUrlTaskResult taskResult = new GetSignedCookiesUrlTaskResult ( ) ; taskResult . setSignedCookiesUrl ( "https://" + domainName + "/cookies?token=" + token ) ; String toReturn = taskResult . serialize ( ) ; log . info ( "Result of " + TASK_NAME + " task: " + toReturn ) ; return toReturn ; } | Create and store signed cookies |
20,977 | public void run ( ) { try { while ( ! complete ) { ContentItem contentItem = new Retrier ( 5 , 4000 , 2 ) . execute ( ( ) -> { return source . getNextContentItem ( ) ; } ) ; if ( contentItem == null ) { break ; } while ( ! retrieveContent ( contentItem ) ) { sleep ( 1000 ) ; } } } catch ( Exception ex ) { logger . error ( "Failed to run to completion" , ex ) ; } finally { shutdown ( ) ; } } | Begins the content retrieval process |
20,978 | public void shutdown ( ) { logger . info ( "Closing Retrieval Manager" ) ; workerPool . shutdown ( ) ; try { workerPool . awaitTermination ( 30 , TimeUnit . MINUTES ) ; } catch ( InterruptedException e ) { } complete = true ; } | Stops the retrieval no further files will be retrieved after those which are in progress have completed . |
20,979 | public String serialize ( T obj ) { try { Marshaller marshaller = context . createMarshaller ( ) ; marshaller . setProperty ( Marshaller . JAXB_FORMATTED_OUTPUT , true ) ; StringWriter writer = new StringWriter ( ) ; marshaller . marshal ( obj , writer ) ; return writer . toString ( ) ; } catch ( JAXBException e ) { throw new XmlSerializationException ( "Exception encountered " + "serializing report: " + getErrorMsg ( e ) , e ) ; } } | Serializes the data stored within a java bean to XML . The bean and any ancillary beans should include JAXB binding annotations . |
20,980 | public T deserialize ( String xml ) { if ( xml == null || xml . equals ( "" ) ) { throw new RuntimeException ( "XML cannot be null or empty" ) ; } else { return deserialize ( new StreamSource ( new StringReader ( xml ) ) ) ; } } | De - serializes XML into an object structure . |
20,981 | public T deserialize ( InputStream stream ) { if ( stream == null ) { throw new RuntimeException ( "Stream cannot be null" ) ; } else { return deserialize ( new StreamSource ( stream ) ) ; } } | De - serializes XML from an InputStream into an object structure . |
20,982 | public Map < String , String > getSpaceProperties ( String spaceId ) { Map < String , String > spaceProps = new HashMap < String , String > ( ) ; Map < String , String > allProps = getAllSpaceProperties ( spaceId ) ; for ( String name : allProps . keySet ( ) ) { if ( ! name . startsWith ( PROPERTIES_SPACE_ACL ) ) { spaceProps . put ( name , allProps . get ( name ) ) ; } } return spaceProps ; } | This method returns all of the space properties EXCEPT the ACLs |
20,983 | public void setNewSpaceProperties ( String spaceId , Map < String , String > spaceProperties ) { setNewSpaceProperties ( spaceId , spaceProperties , getSpaceACLs ( spaceId ) ) ; } | Sets the properties on this space . Maintains the current ACL settings . |
20,984 | public void setNewSpaceProperties ( String spaceId , Map < String , String > spaceProperties , Map < String , AclType > spaceACLs ) { spaceProperties . putAll ( packACLs ( spaceACLs ) ) ; boolean success = false ; int maxLoops = 6 ; for ( int loops = 0 ; ! success && loops < maxLoops ; loops ++ ) { try { doSetSpaceProperties ( spaceId , spaceProperties ) ; success = true ; } catch ( NotFoundException e ) { success = false ; } } if ( ! success ) { throw new StorageException ( "Properties for space " + spaceId + " could not be created. " + "The space cannot be found." ) ; } } | Sets the properties of this space . Note that this method is intentionally not exposed to users as it is not meant to be used for user properties but only for system - level properties . The names and values need to be kept short and the overall number of properties needs to be tightly limited or there will be issues due to provider - specific limitation . |
20,985 | public void deleteSpaceSync ( String spaceId ) { log . debug ( "deleteSpaceSync(" + spaceId + ")" ) ; throwIfSpaceNotExist ( spaceId ) ; Map < String , String > allProps = getAllSpaceProperties ( spaceId ) ; allProps . put ( "is-delete" , "true" ) ; doSetSpaceProperties ( spaceId , allProps ) ; SpaceDeleteWorker deleteWorker = getSpaceDeleteWorker ( spaceId ) ; deleteWorker . run ( ) ; } | This method is only intended to be used by tests! |
20,986 | public Response getSupportedTasks ( @ QueryParam ( "storeID" ) String storeID ) { String msg = "getting suppported tasks(" + storeID + ")" ; try { TaskProvider taskProvider = taskProviderFactory . getTaskProvider ( storeID ) ; List < String > supportedTasks = taskProvider . getSupportedTasks ( ) ; String responseText = SerializationUtil . serializeList ( supportedTasks ) ; return responseOkXml ( msg , responseText ) ; } catch ( Exception e ) { return responseBad ( msg , e , INTERNAL_SERVER_ERROR ) ; } } | Gets a listing of supported tasks for a given provider |
20,987 | @ Path ( "/{taskName}" ) public Response performTask ( @ PathParam ( "taskName" ) String taskName , @ QueryParam ( "storeID" ) String storeID ) { String msg = "performing task(" + taskName + ", " + storeID + ")" ; String taskParameters = null ; try { taskParameters = getTaskParameters ( ) ; } catch ( Exception e ) { return responseBad ( msg , e , INTERNAL_SERVER_ERROR ) ; } try { TaskProvider taskProvider = taskProviderFactory . getTaskProvider ( storeID ) ; String responseText = taskProvider . performTask ( taskName , taskParameters ) ; return responseOk ( msg , responseText ) ; } catch ( UnsupportedTaskException e ) { return responseBad ( msg , e , BAD_REQUEST ) ; } catch ( UnauthorizedException e ) { return responseBad ( msg , e , FORBIDDEN ) ; } catch ( StorageStateException e ) { return responseBad ( msg , e , CONFLICT ) ; } catch ( ServerConflictException e ) { return responseBad ( msg , e , Response . Status . CONFLICT ) ; } catch ( Exception e ) { return responseBad ( msg , e , INTERNAL_SERVER_ERROR ) ; } } | Performs a task |
20,988 | public RetrievedContent getContent ( String spaceID , String contentID , String storeID , String range ) throws InvalidRequestException , ResourceException { try { StorageProvider storage = storageProviderFactory . getStorageProvider ( storeID ) ; return storage . getContent ( spaceID , contentID , range ) ; } catch ( NotFoundException e ) { throw new ResourceNotFoundException ( "get content" , spaceID , contentID , e ) ; } catch ( StorageStateException e ) { throw new ResourceStateException ( "get content" , spaceID , contentID , e ) ; } catch ( IllegalArgumentException e ) { throw new InvalidRequestException ( e . getMessage ( ) ) ; } catch ( Exception e ) { storageProviderFactory . expireStorageProvider ( storeID ) ; throw new ResourceException ( "get content" , spaceID , contentID , e ) ; } } | Retrieves content from a space . |
20,989 | public Map < String , String > getContentProperties ( String spaceID , String contentID , String storeID ) throws ResourceException { try { StorageProvider storage = storageProviderFactory . getStorageProvider ( storeID ) ; return storage . getContentProperties ( spaceID , contentID ) ; } catch ( NotFoundException e ) { throw new ResourceNotFoundException ( "get properties for content" , spaceID , contentID , e ) ; } catch ( Exception e ) { storageProviderFactory . expireStorageProvider ( storeID ) ; throw new ResourceException ( "get properties for content" , spaceID , contentID , e ) ; } } | Retrieves the properties of a piece of content . |
20,990 | public void updateContentProperties ( String spaceID , String contentID , String contentMimeType , Map < String , String > userProperties , String storeID ) throws ResourceException { validateProperties ( userProperties , "update properties for content" , spaceID , contentID ) ; try { StorageProvider storage = storageProviderFactory . getStorageProvider ( storeID ) ; if ( userProperties != null ) { storage . setContentProperties ( spaceID , contentID , userProperties ) ; } } catch ( NotFoundException e ) { throw new ResourceNotFoundException ( "update properties for content" , spaceID , contentID , e ) ; } catch ( StorageStateException e ) { throw new ResourceStateException ( "update properties for content" , spaceID , contentID , e ) ; } catch ( Exception e ) { storageProviderFactory . expireStorageProvider ( storeID ) ; throw new ResourceException ( "update properties for content" , spaceID , contentID , e ) ; } } | Updates the properties of a piece of content . |
20,991 | public String addContent ( String spaceID , String contentID , InputStream content , String contentMimeType , Map < String , String > userProperties , long contentSize , String checksum , String storeID ) throws ResourceException , InvalidIdException , ResourcePropertiesInvalidException { IdUtil . validateContentId ( contentID ) ; validateProperties ( userProperties , "add content" , spaceID , contentID ) ; try { StorageProvider storage = storageProviderFactory . getStorageProvider ( storeID ) ; try { Map < String , String > oldUserProperties = storage . getContentProperties ( spaceID , contentID ) ; if ( userProperties != null ) { oldUserProperties . putAll ( userProperties ) ; String oldMimetype = oldUserProperties . remove ( StorageProvider . PROPERTIES_CONTENT_MIMETYPE ) ; if ( contentMimeType == null || contentMimeType . trim ( ) == "" ) { contentMimeType = oldMimetype ; } oldUserProperties = StorageProviderUtil . removeCalculatedProperties ( oldUserProperties ) ; } userProperties = oldUserProperties ; } catch ( NotFoundException ex ) { } return storage . addContent ( spaceID , contentID , contentMimeType , userProperties , contentSize , checksum , content ) ; } catch ( NotFoundException e ) { throw new ResourceNotFoundException ( "add content" , spaceID , contentID , e ) ; } catch ( ChecksumMismatchException e ) { throw new ResourceChecksumException ( "add content" , spaceID , contentID , e ) ; } catch ( Exception e ) { storageProviderFactory . expireStorageProvider ( storeID ) ; throw new ResourceException ( "add content" , spaceID , contentID , e ) ; } } | Adds content to a space . |
20,992 | public void initializeNotifiers ( Collection < NotificationConfig > notificationConfigs ) { for ( NotificationConfig config : notificationConfigs ) { for ( Notifier notifier : notifiers ) { if ( notifier . getNotificationType ( ) . name ( ) . equalsIgnoreCase ( config . getType ( ) ) ) { notifier . initialize ( config ) ; } } } } | Initializes notifiers using the provided configuration . It is expected that there will be exactly one config for each notifier type . - If there is more than one config for a given type the last configuration of that type in the list will win . - If there is a type not represented in the config list then all notifiers of that type will remain uninitialized . |
20,993 | public void sendNotification ( NotificationType type , String subject , String message , String ... destinations ) { for ( Notifier notifier : notifiers ) { if ( notifier . getNotificationType ( ) . equals ( type ) ) { notifier . notify ( subject , message , destinations ) ; } } } | Sends a notification through all configured notifiers of a given type . |
20,994 | public void sendAdminNotification ( NotificationType type , String subject , String message ) { for ( Notifier notifier : notifiers ) { if ( notifier . getNotificationType ( ) . equals ( type ) ) { notifier . notifyAdmins ( subject , message ) ; } } } | Sends a notification to system administrators through all configured notifiers of a given type . |
20,995 | public String storeData ( String cookieData ) { try { String token = generateToken ( ) ; ensureSpaceExists ( ) ; s3StorageProvider . addHiddenContent ( this . hiddenSpaceName , token , Constants . MEDIA_TYPE_APPLICATION_JSON , IOUtil . writeStringToStream ( cookieData ) ) ; return token ; } catch ( Exception e ) { throw new DuraCloudRuntimeException ( e ) ; } } | Stores string data and returns a token by which that data can be retrieved |
20,996 | public String retrieveData ( String token ) { try { RetrievedContent data = this . s3StorageProvider . getContent ( this . hiddenSpaceName , token ) ; return IOUtil . readStringFromStream ( data . getContentStream ( ) ) ; } catch ( NotFoundException ex ) { return null ; } catch ( Exception ex ) { throw new DuraCloudRuntimeException ( ex ) ; } } | Retrieves string data given its token . |
20,997 | protected Map < String , String > retrieveToFile ( File localFile , RetrievalListener listener ) throws IOException { try { contentStream = new Retrier ( 5 , 4000 , 3 ) . execute ( ( ) -> { return source . getSourceContent ( contentItem , listener ) ; } ) ; } catch ( Exception ex ) { throw new IOException ( ex ) ; } try ( InputStream inStream = contentStream . getStream ( ) ; OutputStream outStream = new FileOutputStream ( localFile ) ; ) { IOUtils . copyLarge ( inStream , outStream ) ; } catch ( IOException e ) { try { deleteFile ( localFile ) ; } catch ( IOException ioe ) { logger . error ( "Exception deleting local file " + localFile . getAbsolutePath ( ) + " due to: " + ioe . getMessage ( ) ) ; } throw e ; } if ( ! checksumsMatch ( localFile , contentStream . getChecksum ( ) ) ) { deleteFile ( localFile ) ; throw new IOException ( "Calculated checksum value for retrieved " + "file does not match properties checksum." ) ; } if ( applyTimestamps ) { applyTimestamps ( contentStream , localFile ) ; } return contentStream . getProperties ( ) ; } | Transfers the remote file stream to the local file |
20,998 | public void generateSchema ( Class ... classes ) throws JAXBException , IOException { if ( ! baseDir . exists ( ) ) { baseDir . mkdirs ( ) ; } JAXBContext context = JAXBContext . newInstance ( classes ) ; context . generateSchema ( this ) ; } | Generates an XML Schema which includes the given classes |
20,999 | public Result createOutput ( String namespaceUri , String defaultFileName ) throws IOException { if ( null == fileName ) { fileName = defaultFileName ; } return new StreamResult ( new File ( baseDir , fileName ) ) ; } | Called by the schema generation process . There is no need to call this method directly . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.