Code Monkey home page Code Monkey logo

semanticdataimport's Introduction

SemanticDataImport

Build Status Code Coverage

Extension for importing CSV-like structured data into MediaWiki pages using Semantic MediaWiki.

It basically turns CSV rows into Semantic Subobjects.

Basic Usage

Content can be saved straight into wikitext pages (only option for older wikis) or also as pure JSON pages (only via SpecialPage interface Special:SDImport).

Namespace configuration

At the time of writting, mappings of CSV columns against Semantic MediaWiki properties can only be done by configuring (custom or not) namespaces in LocalSettings.php.

	# Example NS definition
	define("NS_SDImport", 2000);
	$GLOBALS["wgSDImportDataPage"][NS_SDImport] = array();
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["edit"] = false;
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["separator"] = "\t";
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["delimiter"] = '"';
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["rowobject"] = "SDImport";
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["rowfields"] = array("Page1", "Page2");
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["typefields"] = array("Page", "Page");
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["ref"] = array("ref" => "{{PAGENAME}}");
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["prefields"] = array( "", "" );
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["postfields"] = array( "", "" );
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["json"] = true; # Whether content is stored directly in JSON
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["single"] = false; #Whether to store straight properties-values, but not Subobject (rowobject is ignored)
	$GLOBALS["wgSDImportDataPage"][NS_SDImport]["form"] = false; #Whether to show a form instead of a spreadsheet (as far as single is true)
	$wgExtraNamespaces[NS_SDImport] = "SDImport";
	$GLOBALS['smwgNamespacesWithSemanticLinks'][NS_SDImport] = true;

SDImport interface

There is a preliminary SDImport Special Page (Special:SDImport) that simplifies uploading content (especially for JSON pages)

Properties need to be defined in namespace configuration.

At the time of writing:

  • First column: Page name (in selected namespace)
  • Rest of the columns, according to rowfields values...

JSON schema

Keys defined in JSON schema have precedence in front of what is defined in namespace configuration.

	{
		"meta": {
			"app": "SDI",
			"version": 0.1,
			"rowobject": "Entry",
			"rowfields": ["Relation1", "Relation2"]
		},
		"data": [
			[
				"2",
				"4"
			],
			[
				"2",
				"5"
			]
		]
	}

Useful extensions

If we enable $GLOBALS["wgSDImportDataPage"][NS_SDImport]["edit"] = true; in LocalSettings.php we allow content to be modified by a spreadsheet-like interface.

However we might be interested to edit in another way. For this we recommend to install 2 extensions:

$wgDefaultUserOptions['usebetatoolbar'] = 1; // user option provided by WikiEditor extension

semanticdataimport's People

Contributors

toniher avatar yassin98 avatar

Stargazers

Iván Hernández Cazorla avatar akaPawPaw avatar Karsten Hoffmeyer avatar

Watchers

 avatar James Cloos avatar

Forkers

yassin98

semanticdataimport's Issues

Use dependency injection

I would propose you split your SDImportData into smaller parts which would allow at a later point to import json without having the change the whole parser class.

    $csvDataReder = new CsvDataRender(); // Handling of csv specifc data
    $dataAnnotator = new DataAnnotator() // Create smw annotation

    $dataImportParserFunction = new DataImportParserFunction( $csvDataReder, $dataAnnotator );
    $dataImportParserFunction->parse( ... )

You can see [0] how to use injection in a parser function that splits responsibilities and make the code a bit easier to maintain and understood.

[0] https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/blob/master/src/ParserFunctionFactory.php#L26

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.