<commit_before>/*
 * #%L
 * Tutorials for SCIFIO API
 * %%
 * Copyright (C) 2011 - 2013 Open Microscopy Environment:
 *   - Board of Regents of the University of Wisconsin-Madison
 *   - Glencoe Software, Inc.
 *   - University of Dundee
 * %%
 * To the extent possible under law, the SCIFIO developers have waived
 * all copyright and related or neighboring rights to this tutorial code.
 * 
 * See the CC0 1.0 Universal license for details:
 * http://creativecommons.org/publicdomain/zero/1.0/
 * #L%
 */

package io.scif.tutorials;

import io.scif.Format;
import io.scif.FormatException;
import io.scif.Metadata;
import io.scif.Parser;
import io.scif.SCIFIO;
import io.scif.xml.XMLTools;

import java.io.IOException;

import ome.xml.meta.OMEMetadata;

/**
 * Tutorial on obtaining OME-XML using SCIFIO.
 * 
 * @author <NAME>
 */
public class T1dOpeningOMEXML {

	public static void main(final String... args) throws FormatException,
		IOException
	{
		// Creation of OME-XML metadata in SCIFIO is accomplished via translation.
		// The OME-XML component is essentially a collection of translators, from
		// specific formats to OME-XML, which define how to extract the OME-XML
		// schema.
		// So, we will need to work with a sample image that has a defined
		// translator
		// to OME-XML. Luckily we already have a tutorial which creates a PNG image
		// for us:
		T1cSavingImagePlanes.main(new String[] {});

		// We'll need a context for discovering formats and translators
		final SCIFIO scifio = new SCIFIO();

		// Now we can reference that image via the path:
		final String outPath = "SCIFIOTutorial.png";

		// This is the Metadata object we will translate to OMEXML Metadata;
		Metadata meta = null;

		// NB: we could use the following line here:
		// Reader reader =
		// context.getService(SCIFIO.class).initializer().initializeReader(sampleImage);
		// which would provide us with an initialized reader. We could then obtain
		// its Metadata
		// for Translation:
		// meta = reader.getMetadata();
		// If we were going to continue to use that Reader for more operations this
		// would
		// be quite reasonable. But if we ONLY want the Metadata, it's really doing
		// more than
		// we need. We just need a Parser:

		final Format format = scifio.format().getFormat(outPath);
		final Parser parser = format.createParser();

		// You can see a more in-depth treatment of individual components in T2a and
		// T2b.
		// For now it's enough to know that Parsers parse metadata from a dataset:
		meta = parser.parse(outPath);

		// Now that we have our source Metadata, we will need OME-XML Metadata to
		// translate
		// to:

		final OMEMetadata omexml = new OMEMetadata();
		omexml.setContext(scifio.getContext());

		scifio.translator().translate(meta, omexml, true);

		// Now that we have our OME-XML we can print it:
		final String xml = omexml.getRoot().dumpXML();
		System.out.println(XMLTools.indentXML(xml, 3, true));
	}
}
<commit_msg>T1dOpeningOMEXML: clean up style and comments<commit_after>/*
 * #%L
 * Tutorials for SCIFIO API
 * %%
 * Copyright (C) 2011 - 2013 Open Microscopy Environment:
 *   - Board of Regents of the University of Wisconsin-Madison
 *   - Glencoe Software, Inc.
 *   - University of Dundee
 * %%
 * To the extent possible under law, the SCIFIO developers have waived
 * all copyright and related or neighboring rights to this tutorial code.
 * 
 * See the CC0 1.0 Universal license for details:
 * http://creativecommons.org/publicdomain/zero/1.0/
 * #L%
 */

package io.scif.tutorials;

import io.scif.Format;
import io.scif.FormatException;
import io.scif.Metadata;
import io.scif.Parser;
import io.scif.SCIFIO;
import io.scif.xml.XMLTools;

import java.io.IOException;

import ome.xml.meta.OMEMetadata;

/**
 * Tutorial on obtaining OME-XML using SCIFIO.
 * 
 * @author <NAME>
 */
public class T1dOpeningOMEXML {

	public static void main(final String... args) throws FormatException,
		IOException
	{
		// Creation of OME-XML metadata in SCIFIO is accomplished via translation.
		// The OME-XML component is essentially a collection of translators, from
		// specific formats to OME-XML, which define how to extract the OME-XML
		// schema. So, we will need to work with a sample image that has a defined
		// translator to OME-XML. Luckily we already have a tutorial which creates a
		// PNG image for us:
		T1cSavingImagePlanes.main();

		// We'll need a context for discovering formats and translators
		final SCIFIO scifio = new SCIFIO();

		// Now we can reference that image via the path:
		final String outPath = "SCIFIOTutorial.png";

		// This is the Metadata object we will translate to OMEXML Metadata;
		Metadata meta = null;

		// NB: we could use the following line here:
		//
		// Reader reader = scifio.initializer().initializeReader(sampleImage);
		//
		// which would provide us with an initialized reader. We could then obtain
		// its Metadata for Translation:
		//
		// meta = reader.getMetadata();
		//
		// If we were going to continue to use that Reader for more operations this
		// would be quite reasonable. But if we ONLY want the Metadata, it's really
		// doing more than we need. We just need a Parser:

		final Format format = scifio.format().getFormat(outPath);
		final Parser parser = format.createParser();

		// You can see a more in-depth treatment of individual components in T2a and
		// T2b.
		// For now it's enough to know that Parsers parse metadata from a dataset:
		meta = parser.parse(outPath);

		// Now that we have our source Metadata, we will need OME-XML Metadata to
		// translate to:

		final OMEMetadata omexml = new OMEMetadata();
		omexml.setContext(scifio.getContext());

		scifio.translator().translate(meta, omexml, true);

		// Now that we have our OME-XML we can print it:
		final String xml = omexml.getRoot().dumpXML();
		System.out.println(XMLTools.indentXML(xml, 3, true));
	}
}

{'fraction_non_alphanumeric': 0.09569783197831978, 'fraction_numerical': 0.006266937669376694, 'mean_word_length': 3.326007326007326, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1371973', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1772, 'n_words': 696}