Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get corpus object by corpus name #26

Open
turicas opened this issue Feb 12, 2014 · 3 comments
Open

Get corpus object by corpus name #26

turicas opened this issue Feb 12, 2014 · 3 comments
Milestone

Comments

@turicas
Copy link
Contributor

turicas commented Feb 12, 2014

Currently if I have a corpus named "test" and I want to access its object, I need some code like this:

from pypln.api import PyPLN

pypln = PyPLN('http://demo.pypln.org', ('username', 'myprecious'))
corpora = pypln.corpora()
test_corpus = [corpus for corpus in corpora if corpus.name == 'test']

We should provide better methods of retrieving corpora (better if the API provides special methods for it).
Another possible helper method is something like "get_corpus_or_create", for example:

from pypln.api import PyPLN

pypln = PyPLN('http://demo.pypln.org', ('username', 'myprecious'))
test_corpus = pypln.get_corpus_or_create('test')

We could also see other helper methods in Django's ORM to inspire us and improve library usability.

@turicas turicas added this to the 0.3.0 milestone Feb 12, 2014
@fccoelho
Copy link
Member

Where do we stand in regards to having access restricted only to owners of the corpora?

@flavioamieiro
Copy link
Member

The code already restricts corpora by user. A user can only list and access
corpora created by himself.
On Feb 13, 2014 11:33 AM, "Flávio Codeço Coelho" [email protected]
wrote:

Where do we stand in regards to having access restricted only to owners of
the corpora?

Reply to this email directly or view it on GitHubhttps://github.com//issues/26#issuecomment-34977775
.

@turicas
Copy link
Contributor Author

turicas commented Feb 13, 2014

Without adding a new resource to pypln.web, this problem could be solved with the code:

def get_corpus_or_create(self, corpus_name, corpus_description=''):
    '''Return the `Corpus` object related to a corpus.
    If the corpus does not exist, create it
    '''

    search_corpus = [corpus for corpus in self.corpora() if corpus.name == corpus_name]
    if not search_corpus: # corpus does not exist, need to create it
        return self.add_corpus(corpus_name, corpus_description)
    else:
        return corpus_search[0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants