package org.petapico.npop.topic;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Statement;
import org.nanopub.Nanopub;
import org.petapico.npop.Topic.TopicHandler;

public class MetaboliteSpeciesTopics implements TopicHandler {

	@Override
	public String getTopic(Nanopub np) {
		return getPart1a(np) + ">" + getPart1b(np) + ">" + getPart2(np);
	}

	private String getPart1a(Nanopub np) {
		for (Statement st : np.getAssertion()) {
			if (st.getPredicate().stringValue().equals("http://www.wikidata.org/prop/direct/P703")) {
				return st.getSubject().stringValue() + ">" + st.getObject().stringValue();
			}
		}
		return null;
	}

	private String getPart1b(Nanopub np) {
		for (Statement st : np.getAssertion()) {
			if (st.getPredicate().stringValue().equals("http://semanticscience.org/resource/CHEMINF_000399")) {
				return st.getObject().stringValue();
			}
		}
		return null;
	}

	private String getPart2(Nanopub np) {
		for (Statement st : np.getProvenance()) {
			if (st.getPredicate().stringValue().equals("http://semanticscience.org/resource/SIO_000253")) {
				if (!(st.getObject() instanceof IRI)) continue;
				if (st.getObject().stringValue().equals("http://www.wikidata.org/entity/Q2013")) continue;
				return st.getObject().stringValue();
			}
		}
		return null;
	}

}

@@ -309,17 +309,16 @@
 getPart1
-a
 (np) + %22
@@ -325,24 +325,8 @@
 %3E%22 +
- getPart1b(np) +
  %22%3E%22
@@ -370,17 +370,16 @@
 getPart1
-a
 (Nanopub
@@ -632,263 +632,8 @@
 %09%7D%0A%0A
-%09private String getPart1b(Nanopub np) %7B%0A%09%09for (Statement st : np.getAssertion()) %7B%0A%09%09%09if (st.getPredicate().stringValue().equals(%22http://semanticscience.org/resource/CHEMINF_000399%22)) %7B%0A%09%09%09%09return st.getObject().stringValue();%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%0A
 %09pri

Remove InChIKey again from MetaboliteSpeciesTopics