Anonymous avatar Anonymous committed 3263c1a

Fix warnings

Comments (0)

Files changed (2)

crystallography-importer/src/main/java/net/chempound/crystal/importer/CrystalCml2RdfConverter.java

 import com.hp.hpl.jena.vocabulary.XSD;
 import net.chempound.chemistry.Cml2RdfConverter;
 import net.chempound.chemistry.CmlRdfUtils;
+import net.chempound.crystal.importer.utils.CrystalPropertyMapper;
 import net.chempound.crystal.rdf.ont.ChemAxiom;
 import net.chempound.crystal.rdf.ont.CifDict;
 import net.chempound.crystal.rdf.ont.Cryst;
 import org.xmlcml.cml.element.*;
 
 import java.net.URI;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
 
 import static net.chempound.chemistry.cml.CmlUtils.findFirstModuleByConvention;
 import static net.chempound.crystal.importer.CrystalConstants.*;
-import static net.chempound.crystal.importer.CrystalConstants.CELL_ANGLE_GAMMA;
 import static org.xmlcml.cml.base.CMLConstants.CML_XPATH;
 
 /**
  */
 public class CrystalCml2RdfConverter extends Cml2RdfConverter {
 
-    private static final Map<String,String> DEPRECATED_MAP;
-
-    static {
-        final Map<String,String> map = new HashMap<String, String>();
-        map.put(CifDict.symmetryCellSetting.toString(), CifDict.spaceGroupCrystalSystem.toString());
-        map.put(CifDict.symmetrySpaceGroupNameHall.toString(), CifDict.spaceGroupNameHall.toString());
-        map.put(CifDict.symmetrySpaceGroupNameHM.toString(), CifDict.spaceGroupNameHMAlt.toString());
-        DEPRECATED_MAP = Collections.unmodifiableMap(map);
-    }
-
-    private boolean normaliseUris = true;
+    private final CrystalPropertyMapper propertyMapper = CrystalPropertyMapper.getDefaultMappings();
 
     public Model createModel(final CMLCml cml, final URI baseUri) {
         final CMLModule module = findCrystallographyExperimentModule(cml);
 
         final String hallSpaceGroup = symmetry.getAttributeValue("spaceGroup");
         if (hallSpaceGroup != null) {
-            thisCryst.addProperty(CifDict.symmetrySpaceGroupNameHM, model.createTypedLiteral(hallSpaceGroup, XSDDatatype.XSDstring));
+            thisCryst.addProperty(CifDict.spaceGroupNameHall, model.createTypedLiteral(hallSpaceGroup, XSDDatatype.XSDstring));
         }
     }
 
         final Resource angstroms = model.createResource(UnitsDictionary.U_ANGSTROM);
         final Resource degrees = model.createResource(UnitsDictionary.U_DEGREE);
 
-        for (final CMLScalar cellScalar : crystal.getCellScalars()) {
+        for (final CMLScalar cellScalar : getCellScalars(crystal)) {
 
             final Resource paramBNode = model.createResource(CmlRdf.Scalar);
             paramBNode.addProperty(RDF.value, model.createTypedLiteral(cellScalar.getValue(), XSDDatatype.XSDdouble));
         }
     }
 
+    @SuppressWarnings("deprecation")
+    private List<CMLScalar> getCellScalars(final CMLCrystal crystal) {
+        return crystal.getCellScalars();
+    }
+
     private void attachMoieties(final Model model, final Resource thisCryst, final List<CMLMolecule> moieties) {
         final URI baseUri = URI.create(thisCryst.getURI());
         for (final CMLMolecule moiety : moieties) {
     @Override
     protected String getPropertyUri(final String namespaceURI, final String localPart) {
         final String uri = super.getPropertyUri(namespaceURI, localPart);
-        if (normaliseUris && DEPRECATED_MAP.containsKey(uri)) {
-            return DEPRECATED_MAP.get(uri);
-        }
-        return uri;
+        return propertyMapper.getMapping(uri);
     }
 
     @Override

crystallography-importer/src/main/java/net/chempound/crystal/importer/utils/CrystalPropertyMapper.java

+package net.chempound.crystal.importer.utils;
+
+import net.chempound.crystal.rdf.ont.CifDict;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public final class CrystalPropertyMapper {
+
+    private final Map<String, String> mappings;
+
+    private CrystalPropertyMapper(final Map<String, String> mappings) {
+        this.mappings = mappings;
+    }
+
+    public String getMapping(final String uri) {
+        final String mapping = mappings.get(uri);
+        return mapping == null ? uri : mapping;
+    }
+
+    @SuppressWarnings("deprecation")
+    public static CrystalPropertyMapper getDefaultMappings() {
+        final Map<String, String> mappings = new HashMap<>();
+
+        mappings.put(CifDict.symmetryCellSetting.toString(), CifDict.spaceGroupCrystalSystem.toString());
+        mappings.put(CifDict.symmetrySpaceGroupNameHall.toString(), CifDict.spaceGroupNameHall.toString());
+        mappings.put(CifDict.symmetrySpaceGroupNameHM.toString(), CifDict.spaceGroupNameHMAlt.toString());
+
+        return new CrystalPropertyMapper(mappings);
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.