README.md (2703B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Expand Contractions 22 23 > Expand all contractions to their formal equivalents. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var expandContractions = require( '@stdlib/nlp/expand-contractions' ); 37 ``` 38 39 #### expandContractions( str ) 40 41 Expands all contractions to their formal equivalents. 42 43 ```javascript 44 var str = 'I won\'t be able to get y\'all out of this one.'; 45 var out = expandContractions( str ); 46 // returns 'I will not be able to get you all out of this one.' 47 ``` 48 49 </section> 50 51 <!-- /.usage --> 52 53 <section class="notes"> 54 55 ## Notes 56 57 - This expansion is done via a simple table look-up. Hence, it will not correctly replace contractions for which there are multiple possible expansions such as `"She'd"`, which can be expanded to both `"She would"` or `"She had"`. In such cases, the package expands to a chosen default, in the given example `"She would"`. Should you desire higher accuracy, consider using a fully-fledged NLP disambiguation algorithm for English contractions. 58 59 </section> 60 61 <!-- /.notes --> 62 63 <section class="examples"> 64 65 ## Examples 66 67 <!-- eslint no-undef: "error" --> 68 69 ```javascript 70 var expandContractions = require( '@stdlib/nlp/expand-contractions' ); 71 72 var str = 'I won\'t be able to, sorry.'; 73 var out = expandContractions( str ); 74 // returns 'I will not be able to, sorry.' 75 76 str = 'She\'ll be coming around the mountain...'; 77 out = expandContractions( str ); 78 // returns 'She will be coming around the mountain...' 79 80 str = 'Y\'all\'d be surprised if you know what I\'ll do.'; 81 out = expandContractions( str ); 82 // returns 'You all would be surprised if you know what I will do.' 83 84 str = 'Y\'all\'d\'ve come to the park if y\'all could\'ve, right?'; 85 out = expandContractions( str ); 86 // returns 'You all would have come to the park if you all could have, right?' 87 88 str = 'If Parker hadn\'t been sent off for a foul, they\'d\'ve won.'; 89 out = expandContractions( str ); 90 // returns 'If Parker had not been sent off for a foul, they would have won.' 91 ``` 92 93 </section> 94 95 <!-- /.examples --> 96 97 <section class="links"> 98 99 </section> 100 101 <!-- /.links -->