1

データベースには次のような一連の文字列があります。

仕事から家に帰る。その犬はソファから飛び降りて、玄関で主人を呼びました。彼は顔をきれいに舐めた。

文字列は文の途中から始まります。最初の不完全な文を切り捨てて、「犬がソファから飛び降りて、玄関で主人に挨拶した。顔をきれいに舐めた」から戻る方法を考えたいと思います。

どうすればいいですか?

4

4 に答える 4

1

最も簡単な答え:

str = 'driving home from work. The dog leaped of the sofa to great his master at the door. He licked his face clean.'
str.sub!(/^[^A-Z].+?\./, '').strip!
于 2012-09-18T07:43:39.750 に答える
1

問題は、不完全な文をどのように定義するかです。大文字で始まるすべての文は完全な文であると仮定できます。その場合、コードは次のようになります

str = 'driving home from work. The dog leaped of the sofa to great his master at the door. He licked his face clean.'
sentences = str.split('.')
sentences.shift if sentences[0][0].downcase == sentences[0][0]
sentences.join('.').strip << '.'

少しトリッキーですが、動作します。

于 2012-09-18T07:36:39.893 に答える
0

https://github.com/ged/linkparser

This may help.

于 2012-09-18T07:42:02.403 に答える
0

もしかしてこういうこと?

str = "driving home from work. The dog leaped of the sofa to great his master at the door. He licked his face clean."
str.first == str.first.upcase ? str : str.split(".")[1..-1].join(".").lstrip << "."

大文字で始まるということを文の始まりと仮定すると、それ以外の場合はありえません。考慮すべき他のケース、数値で始まる場合はどうなりますか? 例:1匹の犬が逃げた。犬は… 1 犬… 文ですか?

于 2012-09-18T07:42:13.790 に答える