<commit_before>package org.wikidata.wdtk.examples;

/*
 * #%L
 * Wikidata Toolkit Examples
 * %%
 * Copyright (C) 2014 Wikidata Toolkit Developers
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.wikidata.wdtk.datamodel.interfaces.EntityDocument;
import org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor;
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument;
import org.wikidata.wdtk.datamodel.interfaces.PropertyDocument;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Value;
import org.wikidata.wdtk.storage.wdtkbindings.WdtkDatabaseManager;
import org.wikidata.wdtk.util.Timer;

/**
 * This example application applies an {@link EntityDocumentProcessor} to all
 * documents in a Wikidata dump file. By default, the EntityDocumentProcessor is
 * {@link TutorialDocumentProcessor}.
 * <p>
 * In order to use this application, you must have Wikidata dumps in binary
 * format. By default, the application will use the files
 * <tt>wdtkDatabaseFull-20140804.mapdb</tt> and
 * <tt>wdtkDatabaseFull-20140804.mapdb.p</tt> in the current working directory.
 * The file name can be changed in the source code. If you don't have a binary
 * Wikidata dump in this format, you may have to use the {@link TutorialExample}
 * instead.
 * <p>
 * The application provides several methods to iterate over all or some of the
 * data efficiently. By default, it will simply iterate over all entity
 * documents in the dump.
 *
 * @author <NAME>
 *
 */
public class TutorialExampleDb {

	/**
	 * If this is set to a value other than 0, then any iteration will stop
	 * after that many seconds. This should be used for testing instead of just
	 * terminating the program, since it ensures that the database is closed
	 * properly.
	 */
	static long testTimeOut = 5;

	/**
	 * The name of your database file. Change as appropriate.
	 */
	final static String dbName = "wdtkDatabase";// "wdtkDatabaseNoDesc-20140804";
	final static WdtkDatabaseManager wdtkDatabaseManager = new WdtkDatabaseManager(
			dbName);

	/**
	 * A simple timer that we use to measure progress.
	 */
	final static Timer timer = Timer.getNamedTimer("tutorial-example");

	/**
	 * A counter that we use during processing to print some status messages.
	 */
	static int count;

	/**
	 * The document processor that is used to handle documents.
	 */
	static TutorialDocumentProcessor documentProcessor;

	public static void main(String[] args) {
		documentProcessor = new TutorialDocumentProcessor();

		// Process all entity documents:
		processEntityDocuments(null, null);
		// ==Other options==
		// Process all entity documents that have a value for P570:
		// PropertyIdValue searchProperty = Datamodel
		// .makeWikidataPropertyIdValue("P570"); // P570 = date of death
		// processEntityDocuments(searchProperty, null);<commit_msg>Changed default database name<commit_after>package org.wikidata.wdtk.examples;

/*
 * #%L
 * Wikidata Toolkit Examples
 * %%
 * Copyright (C) 2014 Wikidata Toolkit Developers
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.wikidata.wdtk.datamodel.interfaces.EntityDocument;
import org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor;
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument;
import org.wikidata.wdtk.datamodel.interfaces.PropertyDocument;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Value;
import org.wikidata.wdtk.storage.wdtkbindings.WdtkDatabaseManager;
import org.wikidata.wdtk.util.Timer;

/**
 * This example application applies an {@link EntityDocumentProcessor} to all
 * documents in a Wikidata dump file. By default, the EntityDocumentProcessor is
 * {@link TutorialDocumentProcessor}.
 * <p>
 * In order to use this application, you must have Wikidata dumps in binary
 * format. By default, the application will use the files
 * <tt>wdtkDatabaseFull-20140804.mapdb</tt> and
 * <tt>wdtkDatabaseFull-20140804.mapdb.p</tt> in the current working directory.
 * The file name can be changed in the source code. If you don't have a binary
 * Wikidata dump in this format, you may have to use the {@link TutorialExample}
 * instead.
 * <p>
 * The application provides several methods to iterate over all or some of the
 * data efficiently. By default, it will simply iterate over all entity
 * documents in the dump.
 *
 * @author <NAME>
 *
 */
public class TutorialExampleDb {

	/**
	 * If this is set to a value other than 0, then any iteration will stop
	 * after that many seconds. This should be used for testing instead of just
	 * terminating the program, since it ensures that the database is closed
	 * properly.
	 */
	static long testTimeOut = 5;

	/**
	 * The name of your database file. Change as appropriate.
	 */
	final static String dbName = "wdtkDatabase-20140804";
	final static WdtkDatabaseManager wdtkDatabaseManager = new WdtkDatabaseManager(
			dbName);

	/**
	 * A simple timer that we use to measure progress.
	 */
	final static Timer timer = Timer.getNamedTimer("tutorial-example");

	/**
	 * A counter that we use during processing to print some status messages.
	 */
	static int count;

	/**
	 * The document processor that is used to handle documents.
	 */
	static TutorialDocumentProcessor documentProcessor;

	public static void main(String[] args) {
		documentProcessor = new TutorialDocumentProcessor();

		// Process all entity documents:
		processEntityDocuments(null, null);
		// ==Other options==
		// Process all entity documents that have a value for P570:
		// PropertyIdValue searchProperty = Datamodel
		// .makeWikidataPropertyIdValue("P570"); // P570 = date of death
		// processEntityDocuments(searchProperty, null);
{'fraction_non_alphanumeric': 0.08485294117647059, 'fraction_numerical': 0.012647058823529412, 'mean_word_length': 4.140589569160998, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6442882', 'n_tokens_mistral': 2045, 'n_tokens_neox': 1888, 'n_words': 735}