Giter Site home page Giter Site logo

Comments (5)

a-merezhanyi avatar a-merezhanyi commented on June 9, 2024

Do you really need voca in this case? Doesn't split_whitespace work for you?

let s = "Some sort, of a - sentence."
        .split_whitespace()
        .collect::<Vec<&str>>();
assert_eq!(s, ["Some", "sort,", "of", "a", "-", "sentence."]);

from voca_rs.

mainrs avatar mainrs commented on June 9, 2024

It does in almost all the cases. But I do have similar input to the one you showcased for split::words like XmlHttpRequest. Maybe I have to put something custom made together!

from voca_rs.

a-merezhanyi avatar a-merezhanyi commented on June 9, 2024

Could you please provide a test case to review, so I'd be able to think about the solution?

from voca_rs.

a-merezhanyi avatar a-merezhanyi commented on June 9, 2024

@sirwindfield Please consider the following code snippet, whether this solution works for you?

let s = "Some sort, of a - sentence using LazyLoad with XMLHttpRequest."
    .split_whitespace()
    .collect::<Vec<_>>();
let mut res = Vec::new();
for w in s {
    if w._words().len() > 1 {
        let vec = w._words();
        for v in vec {
            res.push(v);
        }
    } else {
        res.push(w);
    };
}
assert_eq!(
    res,
    [
        "Some", "sort,", "of", "a", "-", "sentence", "using", "Lazy", "Load", "with", "XML",
        "Http", "Request"
    ]
);

Please note that it drops the last point because of words() function behavior; you need to cover such edge cases.

Another possible solution is to cut out the split::words function and to rewrite it for your needs.

from voca_rs.

a-merezhanyi avatar a-merezhanyi commented on June 9, 2024

Closed as it's stalled (workaround has been proposed).

from voca_rs.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.