Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
HI I am looking for a library that'll remove stop words from text in Javascript, my end goal is to calculate tf-idf and then convert the given document into vector space, and all of this is Javascript.
Can anyone point me to a library that'll help me do that.Just a library to remove the stop words would also be great.
Use the stopwords provided by the NLTK library:
stopwords = ['i','me','my','myself','we','our','ours','ourselves','you','your','yours','yourself','yourselves','he','him','his','himself','she','her','hers','herself','it','its','itself','they','them','their','theirs','themselves','what','which','who','whom','this','that','these','those','am','is','are','was','were','be','been','being','have','has','had','having','do','does','did','doing','a','an','the','and','but','if','or','because','as','until','while','of','at','by','for','with','about','against','between','into','through','during','before','after','above','below','to','from','up','down','in','out','on','off','over','under','again','further','then','once','here','there','when','where','why','how','all','any','both','each','few','more','most','other','some','such','no','nor','not','only','own','same','so','than','too','very','s','t','can','will','just','don','should','now']
Then simply pass your string into the following function:
function remove_stopwords(str) {
res = []
words = str.split(' ')
for(i=0;i<words.length;i++) {
word_clean = words[i].split(".").join("")
if(!stopwords.includes(word_clean)) {
res.push(word_clean)
}
}
return(res.join(' '))
}
Example:
remove_stopwords("I will go to the place where there are things for me.")
Result:
I go place things
Just add any words to your NLTK array that aren't covered already.
I think there are no libraries for such thing, you need to download those words from https://www.ranks.nl/stopwords.
And then do replace the words as follows:
text = text.replace(stopword, "")
Here's an array with english stopwords. Hope it helps. From http://www.ranks.nl/stopwords (mentioned in previous answer).
Also, this could be a helpful resource for you.
https://github.com/shiffman/A2Z-F16/tree/gh-pages/week5-analysis
http://shiffman.net/a2z/text-analysis/
var stopwords = ["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any","are","aren't","as","at","be","because","been","before","being","below","between","both","but","by","can't","cannot","could","couldn't","did","didn't","do","does","doesn't","doing","don't","down","during","each","few","for","from","further","had","hadn't","has","hasn't","have","haven't","having","he","he'd","he'll","he's","her","here","here's","hers","herself","him","himself","his","how","how's","i","i'd","i'll","i'm","i've","if","in","into","is","isn't","it","it's","its","itself","let's","me","more","most","mustn't","my","myself","no","nor","not","of","off","on","once","only","or","other","ought","our","ours","ourselves","out","over","own","same","shan't","she","she'd","she'll","she's","should","shouldn't","so","some","such","than","that","that's","the","their","theirs","them","themselves","then","there","there's","these","they","they'd","they'll","they're","they've","this","those","through","to","too","under","until","up","very","was","wasn't","we","we'd","we'll","we're","we've","were","weren't","what","what's","when","when's","where","where's","which","while","who","who's","whom","why","why's","with","won't","would","wouldn't","you","you'd","you'll","you're","you've","your","yours","yourself","yourselves"];
There's a Javascript Library for removing stopwords here: http://geeklad.com/remove-stop-words-in-javascript
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am developing and Django website, and I have an array of some str values(parts of url).When user is redirect to:
https://www.example.com/something/name/
how can system system knows that that is part of that arry.
I alredy have this:
urlpatterns = [
path(r'<name1>, views.example')
]
And Array:
arr = [name1,name2,name3, ....namen] # elements of array are assigned to variables in for loop.
Thank you in advance.
So you need to change urlpatterns to:
path('<str:name>,views.example)
str is data type, and other data type for this use are:
int – Matches zero or any positive integer.
str – Matches any non-empty string, excluding the path separator(‘/’).
slug – Matches any slug string, i.e. a string consisting of alphabets, digits, hyphen and under score.
uuid – Matches a UUID(universal unique identifier).
And function call to:
views.example(request, name = "name_n") # for better code reading use name_1, name_2, .. name_n instead of name1,name2 etc.
and that would be it, enjoy in Django.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
How can I filter array only article data in the separate array?
I would probably use flat map for this
let articleArray = category_articles.flatMap { $0["article"] }
this is of course considering category_articles is an array of dictionary
let seprate_array = category_articles.map {$0.article}
for swift 4.2
let seprate_array = category_articles.flatMap {$0.article}
you can get array of articles in seprate_array array
use map function to extract specific field
You can try
struct Category {
let name:String
let article:String
}
let cats = [Category(name: "1", article: "art1"),Category(name: "2", article: "ar2"),Category(name: "3", article: "art3")]
let arr = cats.map { $0.article }
I use AngularJS to create a page where a user can correct a text (for example grammar, typo ... ).
I cannot use a Textarea because I want to keep trace about changes and let user rollback a correction on each word.
The following code work but it take a few seconds to render with page freeze, specialy on IE like 30 seconds), the text to correct can be very long like in the example.
I use a ng-repeat to display the text (which is an array of word). For each word I text in html if it is punctuation or a <br> or an editable word.
Is there a way to optimize this or to create in a JS way (like a compile html or anything faster)?
PLUNKER
HTML
<div ng-controller="Ctrl1">
Correct the text
<span ng-repeat="word in words track by $index">
<br ng-if="word.br"/>
<span ng-show="(!word.br)&& !word.edited">
<span ng-if="word.editable" class="correct-span" ng-click="word.edited = true">{{word.u}}</span>
<span ng-if="!word.editable">{{word.u}}</span>
</span>
<span class="my-danger" ng-show="(!word.br)&& word.edited">
<input type="text" ng-model="word.u">
<button ng-click="word.edited = false;word.u = word.o">X</button>
</span>
</span>
</div>
My controller :
var myApp = angular.module('myApp', []);
myApp.controller('Ctrl1', ['$scope', function($scope) {
function tools_isString(myVar){
return (typeof myVar == 'string' || myVar instanceof String);
}
/***
* test if object if defined
* #param object
* #returns {boolean}
*/
function tools_defined(object){
return (( typeof object !== undefined) && ( typeof object !== 'undefined') && ( object !== null ) && (object !== "")) ;
}
/**
* test if a word is in array
* #param mot : string
* #param tableau : array list
* #returns {boolean}
*/
function tools_inArray(word, array) {
if(tools_defined(array)&&tools_defined(word)) {
var length = array.length;
if (tools_isString(word)) {
word = word.toLowerCase();
}
for (var i = 0; i < length; i++) {
if (tools_isString(array[i])) {
array[i] = (array[i]).toLowerCase();
}
if (array[i] == word) return true;
}
}
return false;
}
function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function tools_replaceAll(str, find, replace) {
if(str == null ){
return null
}
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
var prepareTextToCorrect = function(inputstring){
//encode new lines
inputstring = tools_replaceAll(inputstring,"<br/>","*br*");
inputstring = tools_replaceAll(inputstring,"<br>","*br*");
// unescape
inputstring = inputstring.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
// remove all the hmtl tags
var rex = /(<([^>]+)>)|(<([^>]+)>)/ig;
inputstring = inputstring.replace(rex , "");
// re encode new lines
inputstring = tools_replaceAll(inputstring,"*br*"," <br/> ");
// separating punctuation from words
var ponctuations = [",","?",",",";",".",":","!","-","_","(",")","«","»","—"];
for(var p in ponctuations){
inputstring = tools_replaceAll(inputstring,ponctuations[p]," "+ponctuations[p]);
}
inputstring = tools_replaceAll(inputstring," "," ");
inputstring = tools_replaceAll(inputstring," "," ");
var elements = inputstring.split(" ");
var res = [];
/**
* "o" : original word
* "u" : word edited by user
* "edited" : if user edited this word
* "editable" : if the word can be edited ( ponctuation and <br> cannot )
*/
for(var i in elements){
if(elements[i].length>0) {
if(elements[i] == "<br/>") {
res.push({
"o": null, "u": null, "edited": false, "br":true
});
} else if (tools_inArray(elements[i], ponctuations)) {
res.push({
"o": elements[i], "u": elements[i], "edited": false,"editable": false , "br":false
});
}else{
res.push({
"o": elements[i], "u": elements[i], "edited": false,"editable": true , "br":false
});
}
}
}
return res ;
};
var text = "Stack Overflow is a question and answer site for professional and enthusiast programmers. It's built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we're working together to build a library of detailed answers to every question about programming.<br/><br/>We're a little bit different from other sites. Here's how:<br/>Ask questions, get answers, no distractions<br/><br/>This site is all about getting answers. It's not a discussion forum. There's no chit-chat.<br/><br/>Just questions...<br/>...and answers.<br/>Good answers are voted up and rise to the top.<br/><br/>The best answers show up first so that they are always easy to find.<br/>accept<br/><br/>The person who asked can mark one answer as accepted.<br/><br/>Accepting doesn't mean it's the best answer, it just means that it worked for the person who asked.<br/>Do Swift-based applications work on OS X 10.9/iOS 7 and lower?<br/>up vote 14 down vote favorite<br/><br/>Will Swift-based applications work on OS X 10.9 (Mavericks)/iOS 7 and lower?<br/><br/>For example, I have a machine running OS X 10.8 (Mountain Lion), and I am wondering if an application I write in Swift will run on it.<br/>ios osx swift<br/>asked Jun 2 '14 at 19:25<br/>MeIr<br/>3,27752557<br/>2 Answers<br/>up vote 4 down vote accept<br/><br/>Swift code can be deployed to OS X 10.9 and iOS 7.0. It will usually crash at launch on older OS versions.<br/>answered Jun 3 '14 at 8:25<br/>Greg Parker<br/>6,21011118<br/>up vote 3 down vote<br/><br/>Apple has announced that Swift apps will be backward compatible with iOS 7 and OS X Mavericks. The WWDC app is written in Swift.<br/>answered Jun 3 '14 at 0:03<br/>Ben Gottlieb<br/>73.3k19161166<br/>Get answers to practical, detailed questions<br/><br/>Focus on questions about an actual problem you have faced. Include details about what you have tried and exactly what you are trying to do.<br/><br/>Ask about...<br/><br/>Specific programming problems<br/>Software algorithms<br/>Coding techniques<br/>Software development tools<br/><br/>Not all questions work well in our format. Avoid questions that are primarily opinion-based, or that are likely to generate discussion rather than answers.<br/><br/>Questions that need improvement may be closed until someone fixes them.<br/><br/>Don't ask about...<br/><br/>Questions you haven't tried to find an answer for (show your work!)<br/>Product or service recommendations or comparisons<br/>Requests for lists of things, polls, opinions, discussions, etc.<br/>Anything not directly related to writing computer programs<br/><br/>Tags make it easy to find interesting questions<br/><br/>Stack Overflow is a question and answer site for professional and enthusiast programmers. It's built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we're working together to build a library of detailed answers to every question about programming.<br/><br/>We're a little bit different from other sites. Here's how:<br/>Ask questions, get answers, no distractions<br/><br/>This site is all about getting answers. It's not a discussion forum. There's no chit-chat.<br/><br/>Just questions...<br/>...and answers.<br/>Good answers are voted up and rise to the top.<br/><br/>The best answers show up first so that they are always easy to find.<br/>accept<br/><br/>The person who asked can mark one answer as accepted.<br/><br/>Accepting doesn't mean it's the best answer, it just means that it worked for the person who asked.<br/>Do Swift-based applications work on OS X 10.9/iOS 7 and lower?<br/>up vote 14 down vote favorite<br/><br/>Will Swift-based applications work on OS X 10.9 (Mavericks)/iOS 7 and lower?<br/><br/>For example, I have a machine running OS X 10.8 (Mountain Lion), and I am wondering if an application I write in Swift will run on it.<br/>ios osx swift<br/>asked Jun 2 '14 at 19:25<br/>MeIr<br/>3,27752557<br/>2 Answers<br/>up vote 4 down vote accept<br/><br/>Swift code can be deployed to OS X 10.9 and iOS 7.0. It will usually crash at launch on older OS versions.<br/>answered Jun 3 '14 at 8:25<br/>Greg Parker<br/>6,21011118<br/>up vote 3 down vote<br/><br/>Apple has announced that Swift apps will be backward compatible with iOS 7 and OS X Mavericks. The WWDC app is written in Swift.<br/>answered Jun 3 '14 at 0:03<br/>Ben Gottlieb<br/>73.3k19161166<br/>Get answers to practical, detailed questions<br/><br/>Focus on questions about an actual problem you have faced. Include details about what you have tried and exactly what you are trying to do.<br/><br/>Ask about...<br/><br/>Specific programming problems<br/>Software algorithms<br/>Coding techniques<br/>Software development tools<br/><br/>Not all questions work well in our format. Avoid questions that are primarily opinion-based, or that are likely to generate discussion rather than answers.<br/><br/>Questions that need improvement may be closed until someone fixes them.<br/><br/>Don't ask about...<br/><br/>Questions you haven't tried to find an answer for (show your work!)<br/>Product or service recommendations or comparisons<br/>Requests for lists of things, polls, opinions, discussions, etc.<br/>Anything not directly related to writing computer programs<br/><br/>Tags make it easy to find interesting questions<br/><br/>Stack Overflow is a question and answer site for professional and enthusiast programmers. It's built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we're working together to build a library of detailed answers to every question about programming.<br/><br/>We're a little bit different from other sites. Here's how:<br/>Ask questions, get answers, no distractions<br/><br/>This site is all about getting answers. It's not a discussion forum. There's no chit-chat.<br/><br/>Just questions...<br/>...and answers.<br/>Good answers are voted up and rise to the top.<br/><br/>The best answers show up first so that they are always easy to find.<br/>accept<br/><br/>The person who asked can mark one answer as accepted.<br/><br/>Accepting doesn't mean it's the best answer, it just means that it worked for the person who asked.<br/>Do Swift-based applications work on OS X 10.9/iOS 7 and lower?<br/>up vote 14 down vote favorite<br/><br/>Will Swift-based applications work on OS X 10.9 (Mavericks)/iOS 7 and lower?<br/><br/>For example, I have a machine running OS X 10.8 (Mountain Lion), and I am wondering if an application I write in Swift will run on it.<br/>ios osx swift<br/>asked Jun 2 '14 at 19:25<br/>MeIr<br/>3,27752557<br/>2 Answers<br/>up vote 4 down vote accept<br/><br/>Swift code can be deployed to OS X 10.9 and iOS 7.0. It will usually crash at launch on older OS versions.<br/>answered Jun 3 '14 at 8:25<br/>Greg Parker<br/>6,21011118<br/>up vote 3 down vote<br/><br/>Apple has announced that Swift apps will be backward compatible with iOS 7 and OS X Mavericks. The WWDC app is written in Swift.<br/>answered Jun 3 '14 at 0:03<br/>Ben Gottlieb<br/>73.3k19161166<br/>Get answers to practical, detailed questions<br/><br/>Focus on questions about an actual problem you have faced. Include details about what you have tried and exactly what you are trying to do.<br/><br/>Ask about...<br/><br/>Specific programming problems<br/>Software algorithms<br/>Coding techniques<br/>Software development tools<br/><br/>Not all questions work well in our format. Avoid questions that are primarily opinion-based, or that are likely to generate discussion rather than answers.<br/><br/>Questions that need improvement may be closed until someone fixes them.<br/><br/>Don't ask about...<br/><br/>Questions you haven't tried to find an answer for (show your work!)<br/>Product or service recommendations or comparisons<br/>Requests for lists of things, polls, opinions, discussions, etc.<br/>Anything not directly related to writing computer programs<br/><br/>Tags make it easy to find interesting questions<br/><br/>Stack Overflow is a question and answer site for professional and enthusiast programmers. It's built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we're working together to build a library of detailed answers to every question about programming.<br/><br/>We're a little bit different from other sites. Here's how:<br/>Ask questions, get answers, no distractions<br/><br/>This site is all about getting answers. It's not a discussion forum. There's no chit-chat.<br/><br/>Just questions...<br/>...and answers.<br/>Good answers are voted up and rise to the top.<br/><br/>The best answers show up first so that they are always easy to find.<br/>accept<br/><br/>The person who asked can mark one answer as accepted.<br/><br/>Accepting doesn't mean it's the best answer, it just means that it worked for the person who asked.<br/>Do Swift-based applications work on OS X 10.9/iOS 7 and lower?<br/>up vote 14 down vote favorite<br/><br/>Will Swift-based applications work on OS X 10.9 (Mavericks)/iOS 7 and lower?<br/><br/>For example, I have a machine running OS X 10.8 (Mountain Lion), and I am wondering if an application I write in Swift will run on it.<br/>ios osx swift<br/>asked Jun 2 '14 at 19:25<br/>MeIr<br/>3,27752557<br/>2 Answers<br/>up vote 4 down vote accept<br/><br/>Swift code can be deployed to OS X 10.9 and iOS 7.0. It will usually crash at launch on older OS versions.<br/>answered Jun 3 '14 at 8:25<br/>Greg Parker<br/>6,21011118<br/>up vote 3 down vote<br/><br/>Apple has announced that Swift apps will be backward compatible with iOS 7 and OS X Mavericks. The WWDC app is written in Swift.<br/>answered Jun 3 '14 at 0:03<br/>Ben Gottlieb<br/>73.3k19161166<br/>Get answers to practical, detailed questions<br/><br/>Focus on questions about an actual problem you have faced. Include details about what you have tried and exactly what you are trying to do.<br/><br/>Ask about...<br/><br/>Specific programming problems<br/>Software algorithms<br/>Coding techniques<br/>Software development tools<br/><br/>Not all questions work well in our format. Avoid questions that are primarily opinion-based, or that are likely to generate discussion rather than answers.<br/><br/>Questions that need improvement may be closed until someone fixes them.<br/><br/>Don't ask about...<br/><br/>Questions you haven't tried to find an answer for (show your work!)<br/>Product or service recommendations or comparisons<br/>Requests for lists of things, polls, opinions, discussions, etc.<br/>Anything not directly related to writing computer programs<br/><br/>Tags make it easy to find interesting questions<br/><br/>" ;
$scope.words = prepareTextToCorrect(text) ;
}]);
Try using ng-if instead of ng-show in your <span> tags. In such a way the browser does not need to render all the DOM nodes that you use when the word is edited. With ng-show the nodes are rendered and then hidden from the DOM using CSS. This means that the browser has to render nodes that you potentially do not use, it is highly probable that you only need to change few words and not the entire document! Try to see if this can improve the rendering time.
Whatever the front-end framework, tracking each word of a text is going to put the browser on its knees, no matter if you have V8, Turbo, 4x4 or whatever.
Just picture the number of nodes. Take a deep deep look at your DOM element, just one of your ng-if spans in your case, and imagine each one of its endless list of attributes being tracked. But you probably already know.
With angular 1.x, you can check if a textarea is $dirty on mouseup, and/or blur, and/on mousemove with a simple directive.
Just wire a service that stores any change made to the whole textarea whenever one of the above events triggers.
In short, it's going to be less expensive to store the whole textarea on every event (after all, its content is just a string, nothing too hard for a browser to handle, even if the string is big — but I'm sure you care about your users and your textarea won't end up to be massive).
To store every change made to the textarea, you can use localStorage and/or a remote DB, using possibly angular locker for localStorage abstractions, and Firebase (AngularFire), which is going to handle automagically any changes made to the textarea given you previously wire the textarea content to a Firebase object.
But your back-end could be of course any data API. I would to suggest to store a limited amount of "Ctrl/Cmd+Z" into localStorage, and for the external DB, well, it's up to you to store infinite versions. That's where Firebase would come in handy, because by forcing you to make adhere to a JSON, you can store by month, week, day, therefore accelerating your retrieval queries for when the end user wants to go back in history.
(I am not sure if this question belongs to the meta website or not, but here we go)
I want to add stackoverflow to the bibliography of a research paper I am writing, and wonder if there is any bibTeX code to do so. I already did that for gnuplot
I searched online, but in most cases the citation goes to a specific thread. In this case, I want to acknowledge SO as a whole, and add a proper citation, probably to the website itself. Hopefully somebody already did this in the past?
As an example, below are the codes I use for R and gnuplot:
#Manual{rproject,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2015},
url = {https://www.R-project.org/},
}
#MISC{gnuplot,
author = {Thomas Williams and Colin Kelley and {many others}},
title = {Gnuplot 5.0: an interactive plotting program},
month = {June},
year = {2015},
howpublished = {\href{http://www.gnuplot.info/}{http://www.gnuplot.info/}}
}
I know that both are software, not website resources, but maybe something along those lines would work. Any feedback is appreciated!
Thanks!
I did not realize this question never got answered. The solution I found was to acknowledge the SO website in the LaTeX code with the following:
This research has made use of the online Q\&A platform {\texttt{stackoverflow}}
(\href{http://stackoverflow.com/}{http://stackoverflow.com/}).
Hope it helps somebody in the future!
Actually, for my paper I am using the following citation:
#misc{stackoverflow,
url={https://stackoverflow.com/},
title={Stack overflow},
year={2008}
}
I hope it helps!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing a phonebook application and one of the functions is for searching the phonebook by name.
The program should print out the names the same way as the user entered them (later I will include the numbers and other info). The phonebook has 100 contacts.
sname is the name that user have entered to search.
name[a] is name list. Is there any other code like strstr? Like its operating if its found printing them if not then print("not found any") something like this:
for(a=1; a<101; a++) {
while(strstr(name[a],sname) != NULL) {
printf(strstr(name[a], sname));
}
}
You can do that: it is an infinite loop.
while(strstr(name[a],sname)!=NULL){
printf("%s\n",strstr(name[a],sname));
}
None of a, name[a], sname change in the conditions or body of the while