Look for books in our kb

    Create book tags by using the authors and the title to find books
    in our knowledge base
967102
def look_for_books(citation_elements, kbs):
    
    title = None
    for el in citation_elements:
        if el['type'] == 'QUOTED':
            title = el
            break

    if title:
        normalized_title = title['title'].upper()
        if normalized_title in kbs['books']:
            line = kbs['books'][normalized_title]
            el = {'type': 'BOOK',
                  'misc_txt': '',
                  'authors': line[0],
                  'title': line[1],
                  'year': line[2].strip(';')}
            citation_elements.append(el)
            citation_elements.remove(title)

    return citation_elements
611734
def find(self, *tags):
        
        tags = list(map(str, tags))
        return self._client.json('corex.find', {'tags': tags})
761116
def load_bookmarks(filename):
    """"""
    bookmarks = _load_all_bookmarks()
    return {k: v for k, v in bookmarks.items() if v[0] == filename}
421957
def entries(self):
        """"""
        Tags = Query()
        tag = self.table.get(Tags.name == self.name)
        posts = tag['post_ids']

        for id in posts:
            post = self.db.posts.get(doc_id=id)
            if not post:  # pragma: no coverage
                raise ValueError("No post found for doc_id %s" % id)
            yield Entry(os.path.join(CONFIG['content_root'], post['filename']), id)
577600
def generate_additional_context(self, matching_datasets):
        """"""
        top_tags = Tag.objects.filter(
            dataset__in=matching_datasets
        ).annotate(
            tag_count=Count('word')
        ).order_by('-tag_count')[:3]

        top_authors = Dataset.objects.filter(
            id__in=matching_datasets
        ).values('uploaded_by').annotate(
            author_count=Count('uploaded_by')
        ).order_by('-author_count')[:3]

        for author in top_authors:
            author['fullName'] = grab_names_from_emails([
                author['uploaded_by']
            ])[author['uploaded_by']]

        return {
            'top_tags': top_tags,
            'top_authors': top_authors
        }
1031661
def tags_all(self):
        
        if 'tags' not in self.database.collection_names():
            print 'Warning: Searching on non-existance tags collection'
            return None

        cursor = self.database['tags'].find({}, {'_id':0, 'md5':1, 'tags':1})
        return [item for item in cursor]
768123
def tag(self, text):
        
        if self.search_method == 'ahocorasick':
            events = self._find_keywords_ahocorasick(text.text)
        elif self.search_method == 'naive':
            events = self._find_keywords_naive(text.text)

        events = self._resolve_conflicts(events)
        if self.mapping:
            for item in events:
                item['type'] = self.map[
                    text.text[item['start']:item['end']]
                ]

        if self.return_layer:
            return events
        else:
            text[self.layer_name] = events
1294872
def get_books(self):
        
        return itunespy.lookup(id=self.artist_id, entity=itunespy.entities['ebook'])[1:]
743131
function postGetTags(id, cb) {
  var q  =
    'SELECT * FROM tags t ' +
      'JOIN posts_tags pt ON t.id = pt.tag_id AND pt.post_id = $1';

  db.getClient(function(err, client, done) {
    client.query(q, [id], function(err, r) {
      if(err) {
        cb(err);
        done(err);
      } else {
        cb(null, r.rows);
        done();
      }
    });
  });
}
908680
def _ref_bib(key, ref):
    '''
    '''
    s = ''

    s += '@{}{{{},\n'.format(ref['type'], key)

    entry_lines = []
    for k, v in ref.items():
        if k == 'type':
            continue

        # Handle authors/editors
        if k == 'authors':
            entry_lines.append('    author = {{{}}}'.format(' and '.join(v)))
        elif k == 'editors':
            entry_lines.append('    editor = {{{}}}'.format(' and '.join(v)))
        else:
            entry_lines.append('    {} = {{{}}}'.format(k, v))

    s += ',\n'.join(entry_lines)
    s += '\n}'

    return s
245159
def get_publications():
    
    books = []
    for link in get_book_links(LINKS):
        books.append(
            _process_book(link)
        )

    return books
7305
public function get_authors()
	{
		$authors = array();
		foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
		{
			$name = null;
			$uri = null;
			$email = null;
			if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
			{
				$name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
			}
			if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
			{
				$uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
			}
			if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
			{
				$email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
			}
			if ($name !== null || $email !== null || $uri !== null)
			{
				$authors[] = $this->registry->create('Author', array($name, $uri, $email));
			}
		}
		if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
		{
			$name = null;
			$url = null;
			$email = null;
			if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
			{
				$name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
			}
			if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
			{
				$url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
			}
			if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
			{
				$email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
			}
			if ($name !== null || $email !== null || $url !== null)
			{
				$authors[] = $this->registry->create('Author', array($name, $url, $email));
			}
		}
		if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
		{
			$authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)));
		}
		foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
		{
			$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
		}
		foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
		{
			$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
		}
		foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
		{
			$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
		}

		if (!empty($authors))
		{
			return array_unique($authors);
		}
		elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
		{
			return $authors;
		}
		elseif ($authors = $this->feed->get_authors())
		{
			return $authors;
		}
		else
		{
			return null;
		}
	}
1273548
def shelves(user_id, options = {})
      options = options.merge(user_id: user_id, v: 2)
      data = request("/shelf/list.xml", options)
      shelves = data["shelves"]

      shelves = data["shelves"]["user_shelf"].map do |s|
        Hashie::Mash.new({
          id:             s["id"],
          name:           s["name"],
          book_count:     s["book_count"],
          exclusive:      s["exclusive_flag"],
          description:    s["description"],
          sort:           s["sort"],
          order:          s["order"],
          per_page:       s["per_page"],
          display_fields: s["display_fields"],
          featured:       s["featured"],
          recommend_for:  s["recommend_for"],
          sticky:         s["sticky"],
        })
      end

      Hashie::Mash.new(
        start:   data["shelves"]["start"].to_i,
        end:     data["shelves"]["end"].to_i,
        total:   data["shelves"]["total"].to_i,
        shelves: shelves
      )
    end
698551
def create_tags(self, entry):
        """"""
        tag_list = [t.lower().strip() for t in entry.tag_string.split(',')]
        for t in tag_list:
            tag, created = self.get_or_create(name=t)
            entry.tags.add(tag)
610877
def tagged(self, tag):
        """"""
        return PostCollection([p for p in self if unicode(tag) in p.tags])
180451
def pull(self,bookName=None,sheetName=None):
        """"""

        # tons of validation
        if bookName is None and self.bookName: bookName=self.bookName
        if sheetName is None and self.sheetName: sheetName=self.sheetName
        if bookName is None: bookName=OR.activeBook()
        if bookName and sheetName is None: sheetName=OR.activeSheet()
        if not bookName or not sheetName:
            print("can't figure out where to pull from! [%s]%s"%(bookName,sheetName))
            return

        # finally doing the thing
        poSheet=OR.getSheet(bookName,sheetName)
        self.bookName=bookName
        self.sheetName=sheetName
        self.desc=poSheet.GetLongName()
        self.colNames=[poCol.GetName() for poCol in poSheet.Columns()]
        self.colDesc=[poCol.GetLongName() for poCol in poSheet.Columns()]
        self.colUnits=[poCol.GetUnits() for poCol in poSheet.Columns()]
        self.colComments=[poCol.GetComments() for poCol in poSheet.Columns()]
        self.colTypes=[poCol.GetType() for poCol in poSheet.Columns()]
        self.colData=[poCol.GetData() for poCol in poSheet.Columns()]
220345
private void tagResources(List<String> resources, List<Tag> tags) {
        // Create a tag request.
        CreateTagsRequest createTagsRequest = new CreateTagsRequest();
        createTagsRequest.setResources(resources);
        createTagsRequest.setTags(tags);

        // Try to tag the Spot request submitted.
        try {
            ec2.createTags(createTagsRequest);
        } catch (AmazonServiceException e) {
            // Write out any exceptions that may have occurred.
            System.out.println("Error terminating instances");
            System.out.println("Caught Exception: " + e.getMessage());
            System.out.println("Reponse Status Code: " + e.getStatusCode());
            System.out.println("Error Code: " + e.getErrorCode());
            System.out.println("Request ID: " + e.getRequestId());
        }

    }