How to create Document objects with JavaScript

There are two methods defined in specifications, createDocument from DOM Core Level 2 and createHTMLDocument from HTML5. The former creates an XML document (including XHTML), the latter creates a HTML document. Both reside, as functions, on the DOMImplementation interface. var impl = document.implementation, xmlDoc = impl.createDocument(namespaceURI, qualifiedNameStr, documentType), htmlDoc = impl.createHTMLDocument(title); In reality, these methods …

Read more

Simple implementation of N-Gram, tf-idf and Cosine similarity in Python

Check out NLTK package: http://www.nltk.org it has everything what you need For the cosine_similarity: def cosine_distance(u, v): “”” Returns the cosine of the angle between vectors v and u. This is equal to u.v / |u||v|. “”” return numpy.dot(u, v) / (math.sqrt(numpy.dot(u, u)) * math.sqrt(numpy.dot(v, v))) For ngrams: def ngrams(sequence, n, pad_left=False, pad_right=False, pad_symbol=None): “”” …

Read more

Difference between screen.availHeight and window.height()

window.outerHeight It’s the height of the window on screen, it includes the page and all the visible browser’s bars (location, status, bookmarks, window title, borders, …). This not the same as jQuery’s $(window).outerHeight(). window.innerHeight or $(window).height() It’s the height of the viewport that shows the website, just the content, no browser’s bars. document.body.clientHeight or $(document).height() …

Read more