@@ -7,20 +7,26 @@ export const MATCH_MODES = {
77
88// Value extractor class
99export class ValueExtractor {
10- // Keyword match
11- static extractByKeyword ( content , keyword ) {
10+ // Helper to get lines array - accepts either content string or pre-split lines array
11+ static getLines ( contentOrLines ) {
12+ if ( ! contentOrLines ) return [ ] ;
13+ if ( Array . isArray ( contentOrLines ) ) return contentOrLines ;
14+ return contentOrLines . split ( '\n' ) ;
15+ }
16+
17+ // Keyword match - now accepts either content string or pre-split lines array
18+ static extractByKeyword ( contentOrLines , keyword ) {
1219 const results = [ ] ;
13- // Handle empty content
14- if ( ! content ) return results ;
15-
16- const lines = content . split ( '\n' ) ;
17-
20+ const lines = this . getLines ( contentOrLines ) ;
21+ if ( lines . length === 0 ) return results ;
22+
1823 // Number regex supporting scientific notation
1924 const numberRegex = / [ + - ] ? \d + (?: \. \d + ) ? (?: [ e E ] [ + - ] ? \d + ) ? / ;
20-
25+ const keywordLower = keyword . toLowerCase ( ) ;
26+
2127 lines . forEach ( ( line , lineIndex ) => {
2228 // Find keyword (case-insensitive)
23- const keywordIndex = line . toLowerCase ( ) . indexOf ( keyword . toLowerCase ( ) ) ;
29+ const keywordIndex = line . toLowerCase ( ) . indexOf ( keywordLower ) ;
2430 if ( keywordIndex !== - 1 ) {
2531 // Find first number after the keyword
2632 const afterKeyword = line . substring ( keywordIndex + keyword . length ) ;
@@ -43,13 +49,12 @@ export class ValueExtractor {
4349 return results ;
4450 }
4551
46- // Column position match
47- static extractByColumn ( content , columnIndex , separator = ' ' ) {
52+ // Column position match - now accepts either content string or pre-split lines array
53+ static extractByColumn ( contentOrLines , columnIndex , separator = ' ' ) {
4854 const results = [ ] ;
49- if ( ! content ) return results ;
55+ const lines = this . getLines ( contentOrLines ) ;
56+ if ( lines . length === 0 ) return results ;
5057
51- const lines = content . split ( '\n' ) ;
52-
5358 lines . forEach ( ( line , lineIndex ) => {
5459 if ( line . trim ( ) ) {
5560 const columns = separator === ' '
@@ -72,13 +77,12 @@ export class ValueExtractor {
7277 return results ;
7378 }
7479
75- // Smart parsing
76- static extractBySmart ( content , type = 'loss' ) {
80+ // Smart parsing - now accepts either content string or pre-split lines array
81+ static extractBySmart ( contentOrLines , type = 'loss' ) {
7782 const results = [ ] ;
78- if ( ! content ) return results ;
83+ const lines = this . getLines ( contentOrLines ) ;
84+ if ( lines . length === 0 ) return results ;
7985
80- const lines = content . split ( '\n' ) ;
81-
8286 // Smart keyword list
8387 const keywords = type === 'loss'
8488 ? [ 'loss' , 'training_loss' , 'train_loss' , 'val_loss' , 'validation_loss' ]
@@ -143,13 +147,12 @@ export class ValueExtractor {
143147 return results ;
144148 }
145149
146- // Regex match (original functionality)
147- static extractByRegex ( content , regex ) {
150+ // Regex match (original functionality) - now accepts either content string or pre-split lines array
151+ static extractByRegex ( contentOrLines , regex ) {
148152 const results = [ ] ;
149- if ( ! content ) return results ;
153+ const lines = this . getLines ( contentOrLines ) ;
154+ if ( lines . length === 0 ) return results ;
150155
151- const lines = content . split ( '\n' ) ;
152-
153156 try {
154157 const regexObj = new RegExp ( regex , 'gi' ) ;
155158 lines . forEach ( ( line , lineIndex ) => {
0 commit comments