<commit_before>! Copyright (C) 2005, 2009 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences sequences.private assocs arrays
delegate.protocols delegate vectors accessors multiline
macros words quotations combinators slots fry strings
combinators.short-circuit ;
IN: xml.data

TUPLE: interpolated var ;
C: <interpolated> interpolated

TUPLE: name
    { space maybe{ string } }
    { main string }
    { url maybe{ string } } ;
C: <name> name

: ?= ( object/f object/f -- ? )
    2dup and [ = ] [ 2drop t ] if ;

: names-match? ( name1 name2 -- ? )
    {
        [ [ space>> ] bi@ ?= ]
        [ [ url>> ] bi@ ?= ]
        [ [ main>> ] bi@ ?= ]
    } 2&& ;

: <simple-name> ( string -- name )
    "" swap f <name> ;

: <null-name> ( string -- name )
    f swap f <name> ;

: assure-name ( string/name -- name )
    dup name? [ <null-name> ] unless ;

TUPLE: attrs { alist sequence } ;
C: <attrs> attrs

: attr@ ( key alist -- index {key,value} )
    [ assure-name ] dip alist>>
    [ first names-match? ] with find ;

M: attrs at*
    attr@ nip [ second t ] [ f f ] if* ;
M: attrs set-at
    2dup attr@ nip [
        2nip set-second
    ] [
        [ assure-name swap 2array ] dip
        [ alist>> ?push ] keep alist<<
    ] if* ;

M: attrs assoc-size alist>> length ;
M: attrs new-assoc drop V{ } new-sequence <attrs> ;
M: attrs >alist alist>> ;

: >attrs ( assoc -- attrs )
    dup [
        V{ } assoc-clone-like
        [ [ assure-name ] dip ] assoc-map
    ] when <attrs> ;
M: attrs assoc-like
    drop dup attrs? [ >attrs ] unless ;

M: attrs clear-assoc
    f >>alist drop ;
M: attrs delete-at
    [ nip ] [ attr@ drop ] 2bi
    [ swap alist>> remove-nth! drop ] [ drop ] if* ;

M: attrs clone<commit_msg>xml.data: use <vector> instead of V{ } new-sequence.<commit_after>! Copyright (C) 2005, 2009 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs combinators
combinators.short-circuit delegate delegate.protocols fry kernel
macros sequences slots strings vectors words ;
IN: xml.data

TUPLE: interpolated var ;
C: <interpolated> interpolated

TUPLE: name
    { space maybe{ string } }
    { main string }
    { url maybe{ string } } ;
C: <name> name

: ?= ( object/f object/f -- ? )
    2dup and [ = ] [ 2drop t ] if ;

: names-match? ( name1 name2 -- ? )
    {
        [ [ space>> ] bi@ ?= ]
        [ [ url>> ] bi@ ?= ]
        [ [ main>> ] bi@ ?= ]
    } 2&& ;

: <simple-name> ( string -- name )
    "" swap f <name> ;

: <null-name> ( string -- name )
    f swap f <name> ;

: assure-name ( string/name -- name )
    dup name? [ <null-name> ] unless ;

TUPLE: attrs { alist sequence } ;
C: <attrs> attrs

: attr@ ( key alist -- index {key,value} )
    [ assure-name ] dip alist>>
    [ first names-match? ] with find ;

M: attrs at*
    attr@ nip [ second t ] [ f f ] if* ;
M: attrs set-at
    2dup attr@ nip [
        2nip set-second
    ] [
        [ assure-name swap 2array ] dip
        [ alist>> ?push ] keep alist<<
    ] if* ;

M: attrs assoc-size alist>> length ;
M: attrs new-assoc drop <vector> <attrs> ;
M: attrs >alist alist>> ;

: >attrs ( assoc -- attrs )
    dup [
        V{ } assoc-clone-like
        [ [ assure-name ] dip ] assoc-map
    ] when <attrs> ;
M: attrs assoc-like
    drop dup attrs? [ >attrs ] unless ;

M: attrs clear-assoc
    f >>alist drop ;
M: attrs delete-at
    [ nip ] [ attr@ drop ] 2bi
    [ swap alist>> remove-nth! drop ] [ drop ] if* ;

M: attrs clone
{'fraction_non_alphanumeric': 0.1524792204069934, 'fraction_numerical': 0.009744912582401835, 'mean_word_length': 2.3365200764818357, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1651621', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1271, 'n_words': 383}