Discussion on api-documentation

19 views
Skip to first unread message

Neha Yadav

unread,
Mar 19, 2009, 2:51:17 AM3/19/09
to conceptnet-users
Hi,
Can anyone help me with the conceptNet Version 3 Documentation, if
available anywhere. Or can guide me how to query ConceptNet version 3
database for results through python. As except the command mentioned
on the HomePage
>>> result = Concept.get('Mumbai',lang_en)
>>> print result
<en: mumbai>
I do not know any other function. Plz anyone if can help...
Thanks,
Neha Yadav

akshay bhat

unread,
Mar 19, 2009, 12:21:02 PM3/19/09
to conceptn...@googlegroups.com
On Thu, Mar 19, 2009 at 12:21 PM, Neha Yadav <neha.compl...@gmail.com> wrote:

Hi,
Can anyone help me with the conceptNet Version 3 Documentation, if
available anywhere. Or can guide me how to query ConceptNet version 3
database for results through python. As except the command mentioned
on the HomePage
>>> result = Concept.get('Mumbai',lang_en)
>>> print result
<en: mumbai>
Conceptnet/CSAMOA ( Django) uses an ORM model. 
result is an  concept object returned by normalization (which involves stemming, stop word removal etc.) of string "Mumbai".
To get different assertion involving concept represented by "Mumbai" you need to access properties of returned object.

try doing:
print result.get_fwd_relations()
etc.

This is code for class concept

class Concept(models.Model):
    language = models.ForeignKey(Language)
    text = models.TextField()
    num_predicates = models.IntegerField(default=0)
    words = models.IntegerField()
    cached_name = models.TextField()

    # Unused:
    last_update = models.DateTimeField()
    last_inference = models.DateTimeField()
    active = models.BooleanField()

    def __unicode__(self):
        return u"<" + self.language.id + ": " + self.text + ">"

    def get_assertions(self, useful_only=True):
        '''Get all assertions about this concept.'''
        conditions = Q(concept1=self) | Q(concept2=self)
        if useful_only:
            return Assertion.useful.filter(conditions)
        else:
            return Assertion.objects.filter(conditions)

    def get_fwd_relations(self):
        '''Get all forward relations from this concept
        A forward relation is an assertion with this concept
        as its first entry.

        Adds an "other" field, for the other concept.
        Returns a genarator expression.'''
        # TODO: port this to a QuerySet subclass to add the 'other'.
        def with_other(assertion):
            assertion.other = assertion.concept2
            return assertion
        return (with_other(assertion) for assertion in self.fwd_relations.all())

    def get_rev_relations(self):
        '''Get all reverse relations from this concept.
        A reverse relation is a relation with this concept
        as its second entry.'''
        def with_other(assertion):
            assertion.other = assertion.concept1
            return assertion
        return (with_other(assertion) for assertion in self.rev_relations.all())

    def get_nlrepr_all(self):
        reprs = {}
        for p in self.fwd_relations.values('text1'):
            reprs.setdefault(p['text1'], 0)
            reprs[p['text1']] += 1
        for p in self.rev_relations.values('text2'):
            reprs.setdefault(p['text2'], 0)
            reprs[p['text2']] += 1
        # FIXME: use key= parameter instead.
        decorated = [(x[1], x[0]) for x in reprs.items()]
        decorated.sort(reverse=True)
        return [r[-1] for r in decorated]

    def get_nlrepr_most_common(self):
        return self.get_nlrepr_all()[0]

    @property
    def canonical_name(self):
        if not self.cached_name:
            # Simple algorithm loosely based off of Rob's
            reprs = self.get_nlrepr_all()
            if len(reprs) == 0: return ''
            def len_penalize_negation(x):
                if negated_re.search(x):
                    return 100 + len(x)
                else:
                    return len(x)
            reprs.sort(key=len_penalize_negation)
            self.cached_name = reprs[0]
            self.save()

        return self.cached_name

    @classmethod
    def get(cls, text, language, auto_create=False):
        if not isinstance(language, Language):
            language = Language.get(language)
        return cls.get_raw(language.nl.normalize(text), language, auto_create)

    @classmethod
    def get_raw(cls, normalized_text, language, auto_create=False):
        if auto_create:
            concept_obj, created = cls.objects.get_or_create(text=normalized_text,language=language)
        else:
            concept_obj = cls.objects.get(text=normalized_text,language=language)
        return concept_obj
    
    class Meta:
        db_table = 'stems'
        unique_together = (('text','language',),)




I do not know any other function. Plz anyone if can help...
Thanks,
Neha Yadav





--
Akshay Uday Bhat.
c.e.f.y.
department of chemical engineering
university institute of chemical technology
mumbai India

“One has the ability and privilege to do one’s respective duty, but has no control over the
results. The fruits of work should not be the motive, for they shall follow one’s actions”
Bhagvad Gita, (2.47)

Neha Yadav

unread,
Mar 20, 2009, 5:25:09 AM3/20/09
to conceptnet-users
Hi
Thanks.

Ken Arnold

unread,
Jun 2, 2009, 3:37:44 PM6/2/09
to conceptnet-users
I realized this group may not know about our new documentation (http://
conceptnet.media.mit.edu/doc/). I updated the API docs page to link to
it: http://groups.google.com/group/conceptnet-users/web/api-documentation?hl=en

-Ken

Joana

unread,
Jun 3, 2009, 7:24:35 AM6/3/09
to conceptnet-users
I'm almost sure that when the new documentation appeared it was more
complete than it is now. Wasn't it?
I'm talking about the link conceptnet4 module, i think there is text
missing.

Joana

On Jun 2, 8:37 pm, Ken Arnold <kenneth.arn...@gmail.com> wrote:
> I realized this group may not know about our new documentation (http://
> conceptnet.media.mit.edu/doc/). I updated the API docs page to link to
> it:http://groups.google.com/group/conceptnet-users/web/api-documentation...
>
> -Ken

Rob Speer

unread,
Jun 8, 2009, 2:58:43 PM6/8/09
to conceptn...@googlegroups.com
There was a considerable amount of text missing under conceptnet4. (I
need to convince people who run the script that publishes
documentation to make sure it actually works first.)

It's back now. Sorry about that.
-- Rob
Reply all
Reply to author
Forward
0 new messages