Page MenuHomePhabricator

Describe in the documentation how to add a basic statement
Open, Needs TriagePublic

Description

In Wikidata an important data type is to connect to another qid.
The documentation currently only describes setting strings.
It could have a basic example how to declare an item as the value of a statement.

Git Repo: https://github.com/addwiki/wikibase-api
Documentation directory: https://github.com/addwiki/wikibase-api/tree/master/docs

Example patch in another repo which adds functionality but also updated the docs: https://github.com/addwiki/mediawiki-api-base/commit/2eb635079cc69e0b84ea1d51a5052358845bee01#diff-e3e2a9bfd88566b05001b02a3f51d286
The files changed in the above commit that update the docs are docs/index.rst and the addition of docs/multipart.rst

Event Timeline

Restricted Application added a project: User-Addshore. · View Herald TranscriptMar 17 2017, 8:27 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Hannolans renamed this task from Describe in the documentation hoe to add a statement 'is a human' to Describe in the documentation how to add a statement 'is a human'.Mar 17 2017, 8:28 AM
Hannolans updated the task description. (Show Details)

@Hannolans

So, there is currently an example in the README that shows how to create a statement (for a string value)

$statementCreator->create(
    new PropertyValueSnak(
        PropertyId::newFromNumber( 1320 ),
        new StringValue( 'New String Value' )
    ),
    'Q777'
);

The StringValue object can be replaced by any object that extends DataValueObject.
So for linking to another entity it needs to be an EntityIdValue.
This needs to be changed to something like:

$statementCreator->create(
    new PropertyValueSnak(
        PropertyId::newFromNumber( 1320 ),
        new EntityIdValue( new ItemId( 'Q99499' ) )
    ),
    'Q777'
);

I'll try and work on documentation soon, it would be great if others could also make PRs with their learnings though!

Addshore removed Addshore as the assignee of this task.Mar 17 2017, 8:32 AM
Addshore moved this task from Incoming to Ready on the Addwiki board.
Addshore added a subscriber: Addshore.

Thanks. In the documentation there is also described to create a new item. in the above example an existing item Q777 is used. What if you create a new item and no qid is available?

Below is the code I have. Adding a string works for new items, but adding a qid not. I used getStatements()->addNewStatement to be able to add it to the new item without a qid.

//Create a new empty item.
$saver = $wbFactory->newRevisionSaver();
$statementCreator = $wbFactory->newStatementCreator();
$edit = new Revision(    new ItemContent( Item::newEmpty() ));
$edit->getContent()->getData()->setDescription( 'nl', 'Kunstenaar');
$edit->getContent()->getData()->setLabel( 'nl', $author->title);

//set RKD id
$edit->getContent()->getData()->getStatements()->addNewStatement(
			 new PropertyValueSnak(PropertyId::newFromNumber( '650'), new StringValue( $rkd_id ))
     );

//human
$edit->getContent()->getData()->getStatements()->addNewStatement(
			 new PropertyValueSnak(PropertyId::newFromNumber( '31' ), new EntityIdValue( new ItemId( 'Q5' )) )
     );

$saver->save( $edit);

Hmmm, I believe that should work.
To make it cleaner to read you can also do.

$saver = $wbFactory->newRevisionSaver();
$statementCreator = $wbFactory->newStatementCreator();

$newItem = Item::newEmpty();
$newItem->getStatements()->addNewStatement( new PropertyValueSnak(PropertyId::newFromNumber( '650'), new StringValue( $rkd_id )));
//etc.

$edit = new Revision(    new ItemContent( $item ));
$saver->save( $edit);

What actually happens with the code you posted above?

I had to add 'use Wikibase\DataModel\Entity\ItemId;' now it works.

@Addshore thanks for your code suggestions.

Restricted Application added a subscriber: TerraCodes. · View Herald TranscriptAug 22 2017, 3:21 PM

Hi

I am a newbie, and I wanted to work on this, can u assign it to me.

Hi and welcome @Dheerajmalisetty! Thanks for your interest! If you have any questions, please ask!

Hi,

Can i actually know where the documentation folder was present?

Hi,

Can i actually know where the documentation folder was present?

https://github.com/addwiki/wikibase-api/blob/master/README.md

Hi,

Can i actually know where the documentation folder was present?

https://github.com/addwiki/wikibase-api/blob/master/README.md

Thank you,
above link provides how to create a statement, but according to question we need to describe in the documentation 'how to declare "is human" is item'.

Declaring that an item is a human is a statement.

Mbch331 added a comment.EditedDec 27 2017, 12:58 PM

Maybe @Addshore or @Hannolans can explain where this needs to be documented. I linked the readme for the library this ticket is about.

Addshore renamed this task from Describe in the documentation how to add a statement 'is a human' to Describe in the documentation how to add a basic statement.Dec 27 2017, 1:01 PM
Addshore updated the task description. (Show Details)
Addshore updated the task description. (Show Details)

So the example in the README currently uses a String value

new StringValue( 'New String Value' )

For a statement, for example, instance of, an EntityIdValue will need to be used.

The constructor for EntityIdValue is as follows:

	public function __construct( EntityId $entityId ) {
		$this->entityId = $entityId;
	}

Do it will be something like:

new EntityIdValue( $itemId )

Should I clone the wikidata seperately or is it to work in wikibase?

Is this bug related to wikimedia?

@Dheerajmalisetty: The project tags of this task show that this task is about https://phabricator.wikimedia.org/project/profile/1490/ . For general questions not directly related to this task, please see https://www.mediawiki.org/wiki/How_to_become_a_MediaWiki_hacker#Feedback.2C_questions_and_support - thanks

Addshore updated the task description. (Show Details)Dec 28 2017, 11:03 AM
Dheerajmalisetty removed Dheerajmalisetty as the assignee of this task.Dec 29 2017, 4:13 AM