Skip to main content

Home/ interesting_sites/ Group items tagged books

Rss Feed Group items tagged

pagetribe .

XML for PHP developers, Part 2: Advanced XML parsing techniques - 0 views

  •  
    $xml = new SimpleXMLElement($xmlstr); foreach ($xml->book as $book) { echo $book->plot, '
    '; }
pagetribe .

Chapter 11: Generic Views - 0 views

  • from django.conf.urls.defaults import * from django.views.generic import list_detail from mysite.books.models import Publisher publisher_info = { 'queryset': Publisher.objects.all(), 'template_name': 'publisher_list_page.html', } urlpatterns = patterns('', (r'^publishers/$', list_detail.object_list, publisher_info) )
  • That’s really all there is to it. All the cool features of generic views come from changing the “info” dictionary passed to the generic view.
  • You might have noticed that sample publisher list template stores all the books in a variable named object_list.
  • ...10 more annotations...
  • it isn’t all that “friendly” to template authors: they have to “just know” that they’re dealing with books here.
  • better name
  • publisher_list;
  • 'template_object_name': 'publisher',
  • If you want to present a list of books by a particular publisher, you can use the same technique:
  • Another common need is to filter the objects given in a list page by some key in the URL. Earlier we hard-coded the publisher’s name in the URLconf, but what if we wanted to write a view that displayed all the books by some arbitrary publisher?
  • “wrap” the object_list generic view
  • # Look up the publisher (and raise a 404 if it can't be found). publisher = get_object_or_404(Publisher, name__iexact=name)
  • Notice that in the preceding example we passed the current publisher being displayed in the extra_context. This is usually a good idea in wrappers of this nature; it lets the template know which “parent” object is currently being browsed.
  • Or, you could use a less obvious but shorter version that relies on the fact that Book.objects.all is itself a callable:
pagetribe .

http://nltk.googlecode.com/svn/trunk/doc/book/ch01.html - 0 views

  • We can count how often a word occurs in a tex
  • Adding two lists creates a new list
  • count the occurrences of a particular word using text1.count('heaven')
  • ...18 more annotations...
  • By convention, m:n means elements m…n-1
  • A consequence of this last change is that the list only has four elements, and accessing a later value generates an error
  • We can join the words of a list to make a single string, or split a string into a list, as follows:
  • 'Monty Python'.split()
  • frequency distribution
  • frequency of each vocabulary item
  • find the 50 most frequent words
  • hese very long words are often hapaxes (i.e. unique) and perhaps it would be better to find frequently occurring long words.
  • Here are all words from the chat corpus that are longer than 7 characters, that occur more than 7 times:   >>> fdist5 = FreqDist(text5) >>> sorted([w for w in set(text5) if len(w) > 7 and fdist5[w] > 7]) ['#14-19teens', '#talkcity_adults', '((((((((((', '........', 'Question', 'actually', 'anything', 'computer', 'cute.-ass', 'everyone', 'football', 'innocent', 'listening', 'remember', 'seriously', 'something', 'together', 'tomorrow', 'watching'] >>>
  • The collocations() function does this for us
  • find bigrams that occur more often than we would expect based on the frequency of individual words.
  • fdist = FreqDist(samples) create a frequency distribution containing the given samples fdist.inc(sample) increment the count for this sample fdist['monstrous'] count of the number of times a given sample occurred fdist.freq('monstrous') frequency of a given sample fdist.N() total number of samples fdist.keys() the samples sorted in order of decreasing frequency for sample in fdist: iterate over the samples, in order of decreasing frequency fdist.max() sample with the greatest count fdist.tabulate() tabulate the frequency distribution fdist.plot() graphical plot of the frequency distribution fdist.plot(cumulative=True) cumulative plot of the frequency distribution fdist1 < fdist2 test if samples in fdist1 occur less frequently than in fdist2
  • it goes through each word in text1, assigning each one in turn to the variable w and performing the specified operation on the variable.
  • The above notation is called a "list comprehension"
  • [f(w) for ...] or [w.f() for ...],
  • Now that we are not double-counting words like This and this
  • by filtering out any non-alphabetic items:   >>> len(set([word.lower() for word in text1 if word.isalpha()]))
  • A collocation is a sequence of words which occur together unusually often. Thus red wine is a collocation, while the wine is not. A characteristic of collocations is that they are resistant to substitution with words that have similar senses — maroon wine sounds definitely odd.
pagetribe .

Lifehacker - Top 10 Obscure Google Search Tricks - Feature - 0 views

  • Using a combination of advanced search operators that specify music files available in an Apache directory listing, you can turn Google into your personal Napster. Go ahead, try this search for Nirvana tracks: -inurl:(htm|html|php) intitle:"index of" +"last modified" +"parent directory" +description +size +(wma|mp3) "Nirvana". (Sub out Nirvana for the band you're interested in; use this one in conjunction with number 7 to find new music, too.) The same type of search recipe can find comic books as well.
pagetribe .

http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html - 0 views

  • Loading your own Corpus If you have a collection of text files that you would like to access using the above methods, you can easily load them with the help of NLTK's PlaintextCorpusReader as follows:
pagetribe .

Chapter 10: Advanced Models - 0 views

  • With ForeignKey fields, it works the other way, too, but it’s slightly different due to the non-symmetrical nature of the relationship. To get a list of books for a given publisher, use publisher.book_set.all(), like this:
  • Making Changes to a Database Schema
  • Run manage.py sqlall [yourapp]
1 - 15 of 15
Showing 20 items per page