Revision 43939
Added by Sandro La Bruzzo about 8 years ago
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/model/serializer/DMFSerializer.java | ||
---|---|---|
1 |
package eu.dnetlib.resolver.model.serializer; |
|
2 |
|
|
3 |
import java.io.ByteArrayOutputStream; |
|
4 |
|
|
5 |
import com.ximpleware.VTDGen; |
|
6 |
import com.ximpleware.VTDNav; |
|
7 |
import com.ximpleware.XMLModifier; |
|
8 |
import eu.dnetlib.resolver.model.ResolvedObject; |
|
9 |
import org.antlr.stringtemplate.StringTemplate; |
|
10 |
import org.apache.commons.logging.Log; |
|
11 |
import org.apache.commons.logging.LogFactory; |
|
12 |
|
|
13 |
/** |
|
14 |
* Created by sandro on 9/21/16. |
|
15 |
*/ |
|
16 |
public class DMFSerializer implements ResolverSerializer { |
|
17 |
|
|
18 |
private static final Log log = LogFactory.getLog(DMFSerializer.class); |
|
19 |
|
|
20 |
private StringTemplate template; |
|
21 |
|
|
22 |
@Override |
|
23 |
public String serializeToXML(final ResolvedObject object) { |
|
24 |
|
|
25 |
template.removeAttribute("object"); |
|
26 |
template.setAttribute("object", object); |
|
27 |
return template.toString(); |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public String serializeReplacingXML(final String xml, final ResolvedObject object) { |
|
32 |
|
|
33 |
try { |
|
34 |
VTDGen vg = new VTDGen(); // Instantiate VTDGen |
|
35 |
XMLModifier xm = new XMLModifier(); //Instantiate XMLModifier |
|
36 |
|
|
37 |
vg.setDoc(xml.getBytes()); |
|
38 |
|
|
39 |
vg.parse(false); |
|
40 |
VTDNav vn = vg.getNav(); |
|
41 |
xm.bind(vn); |
|
42 |
// navigate to <metadata> |
|
43 |
if (vn.toElement(VTDNav.FC, "metadata")) { |
|
44 |
xm.insertBeforeElement("<metadata>" + serializeToXML(object) + "</metadata>"); |
|
45 |
xm.remove(); |
|
46 |
} |
|
47 |
final ByteArrayOutputStream bas = new ByteArrayOutputStream(); |
|
48 |
xm.output(bas); |
|
49 |
return new String(bas.toByteArray()); |
|
50 |
} catch (Throwable e) { |
|
51 |
if (log.isDebugEnabled()) { |
|
52 |
log.debug(String.format("Error on replacing xml: %s", xml)); |
|
53 |
} |
|
54 |
return null; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
public StringTemplate getTemplate() { |
|
59 |
return template; |
|
60 |
} |
|
61 |
|
|
62 |
public void setTemplate(final StringTemplate template) { |
|
63 |
this.template = template; |
|
64 |
} |
|
65 |
} |
modules/dnet-dli/trunk/src/test/java/eu/dnetlib/resolver/DLIRSerializerTest.java | ||
---|---|---|
1 |
package eu.dnetlib.resolver; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.util.Arrays; |
|
6 |
|
|
7 |
import eu.dnetlib.resolver.model.*; |
|
8 |
import eu.dnetlib.resolver.model.serializer.ResolverSerializer; |
|
9 |
import eu.dnetlib.resolver.parser.PMFResolverParser; |
|
10 |
import eu.dnetlib.resolver.store.ConfigurationResolverStoreTestConfig; |
|
11 |
import org.apache.commons.io.IOUtils; |
|
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
14 |
import org.junit.Test; |
|
15 |
import org.junit.runner.RunWith; |
|
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
import org.springframework.test.context.ContextConfiguration; |
|
18 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
19 |
|
|
20 |
/** |
|
21 |
* Created by sandro on 10/4/16. |
|
22 |
*/ |
|
23 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
24 |
@ContextConfiguration(classes = { ConfigurationTestConfig.class, ConfigurationResolverStoreTestConfig.class }) |
|
25 |
public class DLIRSerializerTest { |
|
26 |
|
|
27 |
private static final Log log = LogFactory.getLog(DLIRSerializerTest.class); |
|
28 |
|
|
29 |
@Autowired |
|
30 |
private ResolverSerializer serializer; |
|
31 |
|
|
32 |
@Test |
|
33 |
public void testSerializeScholix() { |
|
34 |
log.debug(serializer.serializeToXML(createScholixMock())); |
|
35 |
} |
|
36 |
|
|
37 |
@Test |
|
38 |
public void testSerializePMF() throws IOException { |
|
39 |
log.debug(serializer.serializeToXML(createPMFMock())); |
|
40 |
} |
|
41 |
|
|
42 |
private ResolvedObject createPMFMock() throws IOException { |
|
43 |
final InputStream resource = getClass().getResourceAsStream("/eu/dnetlib/dli/parser/InputPMFRecord.xml"); |
|
44 |
String xml = IOUtils.toString(resource); |
|
45 |
|
|
46 |
PMFResolverParser parser = new PMFResolverParser(); |
|
47 |
return parser.parseObject(xml); |
|
48 |
} |
|
49 |
|
|
50 |
private ResolvedObject createScholixMock() { |
|
51 |
|
|
52 |
final ResolvedObject mock = new ResolvedObject(); |
|
53 |
mock.setPid("mock"); |
|
54 |
mock.setPidType("mockType"); |
|
55 |
final ObjectProvenance provenance = new ObjectProvenance(); |
|
56 |
provenance.setDatasource("Mock Datasource"); |
|
57 |
mock.setDatasourceProvenance(Arrays.asList(provenance)); |
|
58 |
final ObjectRelation relation = new ObjectRelation(); |
|
59 |
relation.setTargetPID(new PID("mockTarget", "mockType")); |
|
60 |
relation.setTargetType(ObjectType.unknown); |
|
61 |
relation.setRelationProvenance(Arrays.asList(provenance)); |
|
62 |
mock.setRelations(Arrays.asList(relation)); |
|
63 |
return mock; |
|
64 |
} |
|
65 |
|
|
66 |
} |
modules/dnet-dli/trunk/src/test/java/eu/dnetlib/resolver/DLIParserTest.java | ||
---|---|---|
10 | 10 |
import java.util.stream.Collectors; |
11 | 11 |
|
12 | 12 |
import eu.dnetlib.resolver.model.CompletionStatus; |
13 |
import eu.dnetlib.resolver.model.ObjectProvenance; |
|
14 |
import eu.dnetlib.resolver.model.ObjectProvisionMode; |
|
13 | 15 |
import eu.dnetlib.resolver.model.ResolvedObject; |
14 |
import eu.dnetlib.resolver.model.serializer.DMFSerializer; |
|
15 | 16 |
import eu.dnetlib.resolver.parser.DMFDom4jResolverParser; |
16 | 17 |
import eu.dnetlib.resolver.parser.DMFResolverParser; |
18 |
import eu.dnetlib.resolver.parser.PMFResolverParser; |
|
17 | 19 |
import eu.dnetlib.resolver.parser.ScholixResolverParser; |
18 | 20 |
import org.antlr.stringtemplate.StringTemplate; |
19 | 21 |
import org.apache.commons.io.IOUtils; |
... | ... | |
38 | 40 |
|
39 | 41 |
@Test |
40 | 42 |
public void testDMFParser() throws IOException { |
41 |
final InputStream resourceAsStream = getClass().getResourceAsStream("/eu/dnetlib/dli/parser/InputRecord.xml"); |
|
42 |
|
|
43 |
final InputStream resourceAsStream = getClass().getResourceAsStream("/eu/dnetlib/dli/parser/InputRecordDMF.xml"); |
|
43 | 44 |
String str = IOUtils.toString(resourceAsStream); |
44 | 45 |
DMFResolverParser parser = new DMFResolverParser(); |
45 | 46 |
ResolvedObject object = parser.parseObject(str); |
... | ... | |
48 | 49 |
Assert.assertNotNull(object.getTitles()); |
49 | 50 |
Assert.assertNotNull(object.getType()); |
50 | 51 |
object.setTitles(Arrays.asList("TITOLO 1", "TITOLO 2")); |
51 |
|
|
52 | 52 |
final String template = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dli/templates/DMFXML.st")); |
53 | 53 |
final StringTemplate st = new StringTemplate(template); |
54 |
DMFSerializer serializer = new DMFSerializer(); |
|
55 |
serializer.setTemplate(st); |
|
56 | 54 |
|
57 |
final String output = serializer.serializeReplacingXML(str, object); |
|
58 |
|
|
59 |
log.debug(output); |
|
60 | 55 |
} |
61 | 56 |
|
62 | 57 |
@Test |
... | ... | |
83 | 78 |
} |
84 | 79 |
|
85 | 80 |
@Test |
81 |
public void testPMFParser() throws Exception { |
|
82 |
final InputStream resource = getClass().getResourceAsStream("/eu/dnetlib/dli/parser/InputPMFRecord.xml"); |
|
83 |
String xml = IOUtils.toString(resource); |
|
84 |
|
|
85 |
PMFResolverParser parser = new PMFResolverParser(); |
|
86 |
final ResolvedObject resolvedObject = parser.parseObject(xml); |
|
87 |
Assert.assertNotNull(resolvedObject); |
|
88 |
System.out.println("resolvedObject = " + resolvedObject); |
|
89 |
|
|
90 |
Assert.assertNotNull(resolvedObject.getRelations()); |
|
91 |
resolvedObject.getRelations().forEach(it -> System.out.println("relation = " + it)); |
|
92 |
} |
|
93 |
|
|
94 |
@Test |
|
95 |
public void testOpenAIREParser() throws Exception { |
|
96 |
|
|
97 |
final InputStream resource = getClass().getResourceAsStream("/eu/dnetlib/dli/parser/InputRecordOpenaire.xml"); |
|
98 |
|
|
99 |
final String record = IOUtils.toString(resource); |
|
100 |
|
|
101 |
final OpenAireParser parser = new OpenAireParser(); |
|
102 |
final ResolvedObject object = parser.parseObject(record); |
|
103 |
object.setPid("od_______908::ff0270cae25acd9367ef26a53ee5e4a3"); |
|
104 |
object.setPidType("openaire"); |
|
105 |
|
|
106 |
ObjectProvenance provenance = new ObjectProvenance(); |
|
107 |
provenance.setCompletionStatus(CompletionStatus.complete.toString()); |
|
108 |
provenance.setDatasourceId("dli::r3d100010778"); |
|
109 |
provenance.setDatasource("NCBI Nucleotide"); |
|
110 |
provenance.setProvisionMode(ObjectProvisionMode.resolved.toString()); |
|
111 |
object.setDatasourceProvenance(Arrays.asList(provenance)); |
|
112 |
|
|
113 |
System.out.println(object); |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
@Test |
|
86 | 118 |
public void testProteinParser() throws IOException { |
87 | 119 |
final NCBINResolver resolver = new NCBINResolver(); |
88 | 120 |
resolver.setNCBINParser(new NCBINParser()); |
modules/dnet-dli/trunk/src/test/java/eu/dnetlib/resolver/DLIResolverTest.java | ||
---|---|---|
62 | 62 |
|
63 | 63 |
@Test |
64 | 64 |
public void openaireResolverTest() throws Exception { |
65 |
final ResolvedObject pubmedObject = openaireResolver.retrievePID("od_______908::9a2e9533cfe223df763b759c704ae4a8", "openaire"); |
|
65 |
final ResolvedObject pubmedObject = openaireResolver.retrievePID("od_______908::ff0270cae25acd9367ef26a53ee5e4a3", "openaire"); |
|
66 |
System.out.println("pubmedObject = " + pubmedObject); |
|
66 | 67 |
Assert.assertNotNull(pubmedObject); |
67 | 68 |
Assert.assertNotNull(pubmedObject.getAuthors()); |
68 | 69 |
Assert.assertNotNull(pubmedObject.getTitles()); |
modules/dnet-dli/trunk/src/test/java/eu/dnetlib/resolver/ConfigurationTestConfig.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.resolver; |
2 | 2 |
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import eu.dnetlib.resolver.model.serializer.ResolverSerializer; |
|
3 | 6 |
import net.sf.ehcache.Cache; |
7 |
import org.antlr.stringtemplate.StringTemplate; |
|
8 |
import org.apache.commons.io.IOUtils; |
|
4 | 9 |
import org.springframework.cache.ehcache.EhCacheFactoryBean; |
5 | 10 |
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean; |
6 | 11 |
import org.springframework.context.annotation.Bean; |
... | ... | |
10 | 15 |
public class ConfigurationTestConfig { |
11 | 16 |
|
12 | 17 |
@Bean |
18 |
public StringTemplate pmfSerializerTemplate() throws IOException { |
|
19 |
final String template = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dli/templates/PMFXML.st")); |
|
20 |
final StringTemplate st = new StringTemplate(template); |
|
21 |
return st; |
|
22 |
} |
|
23 |
|
|
24 |
@Bean |
|
25 |
public StringTemplate dmfSerializerTemplate() throws IOException { |
|
26 |
final String template = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dli/templates/DMFXML.st")); |
|
27 |
final StringTemplate st = new StringTemplate(template); |
|
28 |
return st; |
|
29 |
} |
|
30 |
|
|
31 |
@Bean |
|
32 |
public StringTemplate scholixSerializerTemplate() throws IOException { |
|
33 |
final String template = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dli/templates/ScholixXML.st")); |
|
34 |
final StringTemplate st = new StringTemplate(template); |
|
35 |
return st; |
|
36 |
} |
|
37 |
|
|
38 |
@Bean |
|
39 |
public ResolverSerializer resolverSerializer() throws IOException { |
|
40 |
final ResolverSerializer serializer = new ResolverSerializer(); |
|
41 |
serializer.setDmfTemplate(dmfSerializerTemplate()); |
|
42 |
serializer.setPmfTemplate(pmfSerializerTemplate()); |
|
43 |
serializer.setScholixTemplate(scholixSerializerTemplate()); |
|
44 |
return serializer; |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
@Bean |
|
13 | 49 |
public ANDSResolver andsResolver() { |
14 | 50 |
final ANDSResolver resolver = new ANDSResolver(); |
15 | 51 |
resolver.setCache((Cache) ResolverCache().getObject()); |
modules/dnet-dli/trunk/src/test/resources/eu/dnetlib/dli/parser/InputRecordOpenaire.xml | ||
---|---|---|
1 |
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
2 |
xmlns:dri="http://www.driver-repository.eu/namespace/dri" |
|
3 |
xmlns:oaf="http://namespace.openaire.eu/oaf"> |
|
4 |
<header> |
|
5 |
<dri:objIdentifier>od_______908::ff0270cae25acd9367ef26a53ee5e4a3</dri:objIdentifier> |
|
6 |
<dri:dateOfCollection/> |
|
7 |
<dri:dateOfTransformation>2016-07-20T21:30:21.586Z</dri:dateOfTransformation> |
|
8 |
<counters> |
|
9 |
<counter_publicationDataset value="1"/> |
|
10 |
<counter_authorship_collected value="4"/> |
|
11 |
<counter_authorship_inferred value="7"/> |
|
12 |
<counter_authorship value="11"/> |
|
13 |
<counter_publicationDataset_inferred value="1"/> |
|
14 |
<counter_doi value="1"/> |
|
15 |
</counters> |
|
16 |
</header> |
|
17 |
<metadata> |
|
18 |
<oaf:entity |
|
19 |
xsi:schemaLocation="http://namespace.openaire.eu/oaf https://www.openaire.eu/schema/0.3/oaf-0.3.xsd"> |
|
20 |
<oaf:result> |
|
21 |
<subject classid="keyword" classname="keyword" schemeid="dnet:result_subject" |
|
22 |
schemename="dnet:result_subject">Poster Presentation |
|
23 |
</subject> |
|
24 |
<title classid="main title" classname="main title" schemeid="dnet:dataCite_title" |
|
25 |
schemename="dnet:dataCite_title">Sanfilippo syndrome registry project and |
|
26 |
natural history studies: an example of patients, parents and researchers |
|
27 |
collaborating for a cure |
|
28 |
</title> |
|
29 |
<dateofacceptance>2014-11-01</dateofacceptance> |
|
30 |
<publisher>BioMed Central</publisher> |
|
31 |
<resulttype classid="publication" classname="publication" |
|
32 |
schemeid="dnet:result_typologies" schemename="dnet:result_typologies"/> |
|
33 |
<language classid="eng" classname="English" schemeid="dnet:languages" |
|
34 |
schemename="dnet:languages"/> |
|
35 |
<journal issn="" eissn="1750-1172" lissn="">Orphanet Journal of Rare |
|
36 |
Diseases |
|
37 |
</journal> |
|
38 |
<source>Orphanet Journal of Rare Diseases</source> |
|
39 |
<country classid="" classname="" schemeid="" schemename=""/> |
|
40 |
<relevantdate classid="" classname="" schemeid="" schemename=""/> |
|
41 |
<description/> |
|
42 |
<embargoenddate/> |
|
43 |
<fulltext/> |
|
44 |
<format/> |
|
45 |
<contributor/> |
|
46 |
<storagedate/> |
|
47 |
<resourcetype classid="" classname="" schemeid="" schemename=""/> |
|
48 |
<device/> |
|
49 |
<size/> |
|
50 |
<version/> |
|
51 |
<lastmetadataupdate/> |
|
52 |
<metadataversionnumber/> |
|
53 |
<originalId>oai:europepmc.org:3221938</originalId> |
|
54 |
<collectedfrom name="Europe PubMed Central" |
|
55 |
id="opendoar____::8b6dd7db9af49e67306feb59a8bdc52c"/> |
|
56 |
<pid classid="doi" classname="doi" schemeid="dnet:pid_types" |
|
57 |
schemename="dnet:pid_types">10.1186/1750-1172-9-S1-P7 |
|
58 |
</pid> |
|
59 |
<pid classid="pmc" classname="pmc" schemeid="dnet:pid_types" |
|
60 |
schemename="dnet:pid_types">PMC4249675 |
|
61 |
</pid> |
|
62 |
<bestlicense classid="OPEN" classname="Open Access" schemeid="dnet:access_modes" |
|
63 |
schemename="dnet:access_modes"/> |
|
64 |
<datainfo> |
|
65 |
<inferred>false</inferred> |
|
66 |
<deletedbyinference>false</deletedbyinference> |
|
67 |
<trust>0.9</trust> |
|
68 |
<inferenceprovenance/> |
|
69 |
<provenanceaction classid="sysimport:crosswalk:repository" |
|
70 |
classname="sysimport:crosswalk:repository" schemeid="dnet:provenanceActions" |
|
71 |
schemename="dnet:provenanceActions"/> |
|
72 |
</datainfo> |
|
73 |
<rels> |
|
74 |
<rel inferred="false" trust="0.9" inferenceprovenance="" |
|
75 |
provenanceaction="sysimport:crosswalk:repository"> |
|
76 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
77 |
>od_______908::4b9e434614a428eb105ba6a2780a0bdf |
|
78 |
</to> |
|
79 |
<ranking>9</ranking> |
|
80 |
<fullname>Feldman, Arleta</fullname> |
|
81 |
</rel> |
|
82 |
<rel inferred="true" trust="0.6654" |
|
83 |
inferenceprovenance="iis::document_referencedDatasets" |
|
84 |
provenanceaction="iis"> |
|
85 |
<to class="isRelatedTo" scheme="dnet:result_result_relations" type="result" |
|
86 |
>datacite____::a51f3ac7b66278e9c1e00232bcaecb2c |
|
87 |
</to> |
|
88 |
<title classid="main title" classname="main title" |
|
89 |
schemeid="dnet:dataCite_title" schemename="dnet:dataCite_title" |
|
90 |
>Sanfilippo Syndrome Registry Project and Natural History Studies: An |
|
91 |
Example of Patients, Parents and Researchers Collaborating for a |
|
92 |
Cure |
|
93 |
</title> |
|
94 |
<dateofacceptance>2014-01-01</dateofacceptance> |
|
95 |
<publisher>Figshare</publisher> |
|
96 |
<resulttype classid="dataset" classname="dataset" |
|
97 |
schemeid="dnet:result_typologies" schemename="dnet:result_typologies"/> |
|
98 |
</rel> |
|
99 |
<rel inferred="false" trust="0.9" inferenceprovenance="" |
|
100 |
provenanceaction="sysimport:crosswalk:repository"> |
|
101 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
102 |
>od_______908::56b8d7bd3adfc724ebf2fc4f7581d483 |
|
103 |
</to> |
|
104 |
<ranking>3</ranking> |
|
105 |
<fullname>Siedman, Jennifer</fullname> |
|
106 |
</rel> |
|
107 |
<rel inferred="false" trust="0.9" inferenceprovenance="" |
|
108 |
provenanceaction="sysimport:crosswalk:repository"> |
|
109 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
110 |
>od_______908::7c6dcef6ea6ec7f1610d9b15f4c50370 |
|
111 |
</to> |
|
112 |
<ranking>2</ranking> |
|
113 |
<fullname>Siedman, Stuart</fullname> |
|
114 |
</rel> |
|
115 |
<rel inferred="true" trust="0.9" inferenceprovenance="" |
|
116 |
provenanceaction="sysimport:crosswalk:repository"> |
|
117 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
118 |
>dedup_wf_001::5f19e647f8a2e3a28d722484819feeef |
|
119 |
</to> |
|
120 |
<ranking>4</ranking> |
|
121 |
<fullname>Levy, Paul</fullname> |
|
122 |
</rel> |
|
123 |
<rel inferred="false" trust="0.9" inferenceprovenance="" |
|
124 |
provenanceaction="sysimport:crosswalk:repository"> |
|
125 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
126 |
>od_______908::913d9b593a156f953a54f8b9d1203880 |
|
127 |
</to> |
|
128 |
<ranking>10</ranking> |
|
129 |
<fullname>PleHcha, Robert</fullname> |
|
130 |
</rel> |
|
131 |
<rel inferred="true" trust="0.9" inferenceprovenance="" |
|
132 |
provenanceaction="sysimport:crosswalk:repository"> |
|
133 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
134 |
>dedup_wf_001::3e4d9ae55b46ec26b0326778da189aec |
|
135 |
</to> |
|
136 |
<ranking>1</ranking> |
|
137 |
<fullname>Wood, Jill</fullname> |
|
138 |
</rel> |
|
139 |
<rel inferred="true" trust="0.9" inferenceprovenance="" |
|
140 |
provenanceaction="sysimport:crosswalk:repository"> |
|
141 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
142 |
>dedup_wf_001::33e0bc567879a7d22b28533be640ab51 |
|
143 |
</to> |
|
144 |
<ranking>7</ranking> |
|
145 |
<fullname>Flanigan, Kevin</fullname> |
|
146 |
</rel> |
|
147 |
<rel inferred="true" trust="0.9" inferenceprovenance="" |
|
148 |
provenanceaction="sysimport:crosswalk:repository"> |
|
149 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
150 |
>dedup_wf_001::1a32d94a4ad18c0aef4058b544da239d |
|
151 |
</to> |
|
152 |
<ranking>5</ranking> |
|
153 |
<fullname>Brown, Kyle</fullname> |
|
154 |
</rel> |
|
155 |
<rel inferred="true" trust="0.9" inferenceprovenance="" |
|
156 |
provenanceaction="sysimport:crosswalk:repository"> |
|
157 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
158 |
>dedup_wf_001::fa6af6669fb10add0963a033859a8947 |
|
159 |
</to> |
|
160 |
<ranking>11</ranking> |
|
161 |
<fullname>Ekins, Sean</fullname> |
|
162 |
</rel> |
|
163 |
<rel inferred="true" trust="0.9" inferenceprovenance="" |
|
164 |
provenanceaction="sysimport:crosswalk:repository"> |
|
165 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
166 |
>dedup_wf_001::ddd713e4aa7795462fb4f0d3db09551a |
|
167 |
</to> |
|
168 |
<ranking>8</ranking> |
|
169 |
<fullname>Marques, Raquel</fullname> |
|
170 |
</rel> |
|
171 |
<rel inferred="true" trust="0.9" inferenceprovenance="" |
|
172 |
provenanceaction="sysimport:crosswalk:repository"> |
|
173 |
<to class="hasAuthor" scheme="dnet:person_result_relations" type="person" |
|
174 |
>dedup_wf_001::0cf6c28bee5d8fa6753afb05507ddba4 |
|
175 |
</to> |
|
176 |
<ranking>6</ranking> |
|
177 |
<fullname>McBride, Kim</fullname> |
|
178 |
</rel> |
|
179 |
</rels> |
|
180 |
<children> |
|
181 |
<instance id="opendoar____::8b6dd7db9af49e67306feb59a8bdc52c"> |
|
182 |
<licence classid="OPEN" classname="Open Access" schemeid="dnet:access_modes" |
|
183 |
schemename="dnet:access_modes"/> |
|
184 |
<instancetype classid="0001" classname="Article" |
|
185 |
schemeid="dnet:publication_resource" |
|
186 |
schemename="dnet:publication_resource"/> |
|
187 |
<hostedby name="Europe PubMed Central" |
|
188 |
id="opendoar____::8b6dd7db9af49e67306feb59a8bdc52c"/> |
|
189 |
<webresource> |
|
190 |
<url>http://europepmc.org/articles/PMC4249675</url> |
|
191 |
</webresource> |
|
192 |
</instance> |
|
193 |
</children> |
|
194 |
</oaf:result> |
|
195 |
</oaf:entity> |
|
196 |
</metadata> |
|
197 |
</result> |
modules/dnet-dli/trunk/src/test/resources/eu/dnetlib/dli/parser/inputPMFRecord.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<oai:record xmlns:dc="http://purl.org/dc/elements/1.1/" |
|
3 |
xmlns:dr="http://www.driver-repository.eu/namespace/dr" |
|
4 |
xmlns:dri="http://www.driver-repository.eu/namespace/dri" |
|
5 |
xmlns:pmf="http://namespace.dnet.eu/pmf" |
|
6 |
xmlns:oai="http://www.openarchives.org/OAI/2.0/"> |
|
7 |
<oai:header> |
|
8 |
<dri:objIdentifier>od______2367::0001a50c6388e9bfcb791a924ec4b837</dri:objIdentifier> |
|
9 |
<dri:recordIdentifier>oai:pumaoai.isti.cnr.it:cnr.imati/cnr.ian.pv/1999-PP-018</dri:recordIdentifier> |
|
10 |
<dri:dateOfCollection/> |
|
11 |
<dri:mdFormat/> |
|
12 |
<dri:mdFormatInterpretation/> |
|
13 |
<dri:repositoryId>10d18b66-1d2a-4579-9adc-aa57b0821c7f_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId> |
|
14 |
<dr:objectIdentifier/> |
|
15 |
<dr:dateOfCollection>2016-06-24T09:26:13.886Z</dr:dateOfCollection> |
|
16 |
<dr:dateOfTransformation/> |
|
17 |
<pmf:datasourceprefix>od______2367</pmf:datasourceprefix> |
|
18 |
</oai:header> |
|
19 |
<oai:metadata> |
|
20 |
<pmf:pid type="doi">10.1016/j.jmgm.2014.05.002</pmf:pid> |
|
21 |
<dc:title>Anisotropic mechanisms for multiphasic unipolar electrograms. Simulation studies and experimental recordings</dc:title> |
|
22 |
<dc:creator>Colli Franzone, Piero,</dc:creator> |
|
23 |
<dc:creator>Guerri, Luciano,</dc:creator> |
|
24 |
<dc:creator>Pennacchio, Micol,</dc:creator> |
|
25 |
<dc:creator>Taccardi, Bruno</dc:creator> |
|
26 |
<dc:date>1999-09-30</dc:date> |
|
27 |
<dc:description>The origin of the multiple, complex morphologies observed in |
|
28 |
unipolar epicardial electrograms, and their relationships with myocardial |
|
29 |
architecture, have not been fully elucidated. To clarify this problem we |
|
30 |
simulated electrograms (EGs) with a model representing the heart as an |
|
31 |
anisotropic bidomain with unequal anisotropy ratio, ellipsoidal ventricular |
|
32 |
geometry, transmural fiber rotation, epi-endocardial obliqueness of fiber |
|
33 |
direction and a simplified conduction system. The electrograms were compared |
|
34 |
with those directly recorded from the surface of isolated dog hearts immersed |
|
35 |
in a conducting medium. The model accurately reproduced the recorded EG |
|
36 |
morphologies for excitation wave fronts that reach the recording sites by |
|
37 |
spreading either along or across fibers.The |
|
38 |
origin of the multiple waves that constitute the QRS complex could be better |
|
39 |
understood after splitting the current sources, the potential distributions and |
|
40 |
the EGs into a field component (further subdivided into an axial and a conormal component) and a "reference" component. The split model provides an explanation of the interaction between the three-dimensional geometry and direction of |
|
41 |
propagation of a spreading wave front, the architecture of the fibers through |
|
42 |
which excitation is spreading, the potential distributions and the QRS wave |
|
43 |
forms. Because epicardial potentials, electrograms and isochrone contours can be |
|
44 |
computed noninvasively from body surface measurements, interpreting epicardial |
|
45 |
EGs in terms of intramural events may have clinical relevance. |
|
46 |
</dc:description> |
|
47 |
<dc:subject>Electrograms, bidomain model, reference potential, cardiac potential maps, anisotropic propagation, source splitting</dc:subject> |
|
48 |
<dc:subject>info:eu-repo/classification/msc/78A70,65N30</dc:subject> |
|
49 |
<dc:type>publication</dc:type> |
|
50 |
<pmf:hostedBy id="opendoar____::2367" name="PUblication MAnagement"/> |
|
51 |
<pmf:collectedFrom id="opendoar____::2367" name="PUblication MAnagement" mode="collected" completionStatus="complete">opendoar____::2367</pmf:collectedFrom> |
|
52 |
<pmf:relatedIdentifier type="dataset" pid="r39633d1e8c4::e45092771f9073a58ec4b831020b9340" pidType="openaire"/> |
|
53 |
<pmf:relatedIdentifier type="publication" pid="10.1016/j.jmgm.2014.05.002" pidType="doi"/> |
|
54 |
|
|
55 |
</oai:metadata> |
|
56 |
<pmf:about xmlns:oai="http://www.openarchives.org/OAI/2.0/"> |
|
57 |
<pmf:datainfo> |
|
58 |
<pmf:completionStatus>complete</pmf:completionStatus> |
|
59 |
<pmf:provisionMode>collected</pmf:provisionMode> |
|
60 |
</pmf:datainfo> |
|
61 |
</pmf:about> |
|
62 |
</oai:record> |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/parser/UtilityParser.java | ||
---|---|---|
21 | 21 |
final Node currentNode = new Node(); |
22 | 22 |
final Map<String, String> currentAttributes = new HashMap<>(); |
23 | 23 |
int t = vn.getText(); |
24 |
currentNode.setTextValue(vn.toNormalizedString(t)); |
|
24 |
if (t >= 0) |
|
25 |
currentNode.setTextValue(vn.toNormalizedString(t)); |
|
25 | 26 |
|
26 | 27 |
attributes.forEach(attributeKey -> { |
27 | 28 |
try { |
... | ... | |
41 | 42 |
List<String> results = new ArrayList<>(); |
42 | 43 |
ap.selectXPath(xpath); |
43 | 44 |
while (ap.evalXPath() != -1) { |
44 |
|
|
45 | 45 |
int t = vn.getText(); |
46 |
results.add(vn.toNormalizedString(t)); |
|
46 |
if (t > -1) results.add(vn.toNormalizedString(t));
|
|
47 | 47 |
} |
48 | 48 |
return results; |
49 | 49 |
} |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/parser/PMFResolverParser.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.resolver.parser; |
2 | 2 |
|
3 |
import java.io.ByteArrayInputStream; |
|
4 |
import javax.xml.stream.XMLInputFactory; |
|
5 |
import javax.xml.stream.XMLStreamConstants; |
|
6 |
import javax.xml.stream.XMLStreamReader; |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Arrays; |
|
5 |
import java.util.List; |
|
7 | 6 |
|
8 |
import eu.dnetlib.resolver.model.ResolvedObject; |
|
7 |
import com.ximpleware.AutoPilot; |
|
8 |
import com.ximpleware.VTDGen; |
|
9 |
import com.ximpleware.VTDNav; |
|
10 |
import eu.dnetlib.resolver.model.*; |
|
11 |
import eu.dnetlib.resolver.parser.UtilityParser.Node; |
|
9 | 12 |
|
10 | 13 |
/** |
11 | 14 |
* Created by sandro on 9/13/16. |
... | ... | |
15 | 18 |
@Override |
16 | 19 |
public ResolvedObject parseObject(final String record) { |
17 | 20 |
try { |
18 |
XMLInputFactory factory = XMLInputFactory.newInstance(); |
|
19 |
XMLStreamReader parser = factory.createXMLStreamReader(new ByteArrayInputStream(record.getBytes())); |
|
20 |
ResolvedObject currentObject = new ResolvedObject(); |
|
21 |
while (parser.hasNext()) { |
|
22 |
int event = parser.next(); |
|
23 |
if (event == XMLStreamConstants.END_ELEMENT) { |
|
21 |
final ResolvedObject parsedObject = new ResolvedObject(); |
|
22 |
final VTDGen vg = new VTDGen(); |
|
23 |
vg.setDoc(record.getBytes()); |
|
24 |
vg.parse(true); |
|
24 | 25 |
|
25 |
}
|
|
26 |
if (event == XMLStreamConstants.START_ELEMENT) {
|
|
26 |
final VTDNav vn = vg.getNav();
|
|
27 |
final AutoPilot ap = new AutoPilot(vn);
|
|
27 | 28 |
|
28 |
} |
|
29 |
ap.declareXPathNameSpace("pmf", "http://namespace.dnet.eu/pmf"); |
|
30 |
final List<Node> pid = UtilityParser.getTextValuesWithAttributes(ap, vn, "//pmf:pid", Arrays.asList("type")); |
|
31 |
|
|
32 |
if (pid != null && pid.size() > 0) { |
|
33 |
final String currentPid = pid.get(0).getTextValue(); |
|
34 |
final String currentPidType = pid.get(0).getAttributes().get("type"); |
|
35 |
parsedObject.setPid(currentPid); |
|
36 |
parsedObject.setPidType(currentPidType); |
|
29 | 37 |
} |
30 |
return currentObject; |
|
38 |
|
|
39 |
List<Node> collectedFromNodes = |
|
40 |
UtilityParser.getTextValuesWithAttributes(ap, vn, "//pmf:collectedFrom", Arrays.asList("name", "id", "mode", "completionStatus")); |
|
41 |
|
|
42 |
final List<ObjectProvenance> provenances = new ArrayList<>(); |
|
43 |
|
|
44 |
if (collectedFromNodes != null && collectedFromNodes.size() > 0) { |
|
45 |
collectedFromNodes.forEach(it -> { |
|
46 |
final ObjectProvenance provenance = new ObjectProvenance(); |
|
47 |
provenance.setDatasourceId(it.getAttributes().get("id")); |
|
48 |
provenance.setDatasource(it.getAttributes().get("name")); |
|
49 |
provenance.setProvisionMode(it.getAttributes().get("mode")); |
|
50 |
provenance.setCompletionStatus(it.getAttributes().get("completionStatus")); |
|
51 |
provenances.add(provenance); |
|
52 |
}); |
|
53 |
} |
|
54 |
|
|
55 |
parsedObject.setDatasourceProvenance(provenances); |
|
56 |
parsedObject.setCompletionStatus(UtilityParser.getSingleValue(ap, vn, "//pmf:completionStatus")); |
|
57 |
|
|
58 |
List<Node> relatedIdentifiers = |
|
59 |
UtilityParser.getTextValuesWithAttributes(ap, vn, "//pmf:relatedIdentifier", Arrays.asList("type", "pid", "pidType")); |
|
60 |
|
|
61 |
if (relatedIdentifiers != null && relatedIdentifiers.size() > 0) { |
|
62 |
final List<ObjectRelation> relations = new ArrayList<>(); |
|
63 |
relatedIdentifiers.forEach(relation -> { |
|
64 |
final String currentPid = relation.getAttributes().get("pid"); |
|
65 |
final String currentPidType = relation.getAttributes().get("pidType"); |
|
66 |
final String currentType = relation.getAttributes().get("type"); |
|
67 |
final ObjectRelation currenRelation = new ObjectRelation(); |
|
68 |
currenRelation.setTargetPID(new PID(currentPid, currentPidType)); |
|
69 |
currenRelation.setCompletionStatus(CompletionStatus.incomplete.toString()); |
|
70 |
currenRelation.setSourcePid(parsedObject.getPid()); |
|
71 |
currenRelation.setTargetType(ObjectType.valueOf(currentType)); |
|
72 |
if (parsedObject.getDatasourceProvenance() != null && parsedObject.getDatasourceProvenance().size() > 0) { |
|
73 |
final ObjectProvenance provenance = parsedObject.getDatasourceProvenance().get(0); |
|
74 |
|
|
75 |
final ObjectProvenance newProvenance = new ObjectProvenance(); |
|
76 |
newProvenance.setCompletionStatus(CompletionStatus.incomplete.toString()); |
|
77 |
newProvenance.setDatasourceId(provenance.getDatasourceId()); |
|
78 |
newProvenance.setDatasource(provenance.getDatasource()); |
|
79 |
newProvenance.setProvisionMode(provenance.getProvisionMode()); |
|
80 |
currenRelation.setRelationProvenance(Arrays.asList(newProvenance)); |
|
81 |
} |
|
82 |
|
|
83 |
relations.add(currenRelation); |
|
84 |
}); |
|
85 |
parsedObject.setRelations(relations); |
|
86 |
} |
|
87 |
|
|
88 |
ap.declareXPathNameSpace("dc", "http://purl.org/dc/elements/1.1/"); |
|
89 |
final List<String> authorsNode = UtilityParser.getTextValue(ap, vn, "//dc:creator"); |
|
90 |
parsedObject.setAuthors(authorsNode); |
|
91 |
parsedObject.setTitles(UtilityParser.getTextValue(ap, vn, "//dc:title")); |
|
92 |
|
|
93 |
parsedObject.setDescription(UtilityParser.getSingleValue(ap, vn, "//dc:description")); |
|
94 |
parsedObject.setDate(UtilityParser.getSingleValue(ap, vn, "//dc:date")); |
|
95 |
List<Node> subjects = UtilityParser.getTextValuesWithAttributes(ap, vn, "//dc:subject", Arrays.asList("scheme")); |
|
96 |
if (subjects != null && subjects.size() > 0) { |
|
97 |
final List<SubjectType> currentSubjects = new ArrayList<>(); |
|
98 |
subjects.forEach(it -> { |
|
99 |
|
|
100 |
String scheme = it.getAttributes().get("scheme"); |
|
101 |
if (scheme == null) |
|
102 |
scheme = "unknown"; |
|
103 |
currentSubjects.add(new SubjectType(scheme, it.getTextValue())); |
|
104 |
}); |
|
105 |
|
|
106 |
parsedObject.setSubjects(currentSubjects); |
|
107 |
} |
|
108 |
|
|
109 |
setType(parsedObject, UtilityParser.getSingleValue(ap, vn, "//dc:type")); |
|
110 |
|
|
111 |
return parsedObject; |
|
31 | 112 |
} catch (Throwable e) { |
32 | 113 |
log.debug("Input record: " + record); |
33 | 114 |
log.error("Error on parsing record ", e); |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/parser/AbstractResolverParser.java | ||
---|---|---|
27 | 27 |
return attributesMap; |
28 | 28 |
} |
29 | 29 |
|
30 |
protected boolean setDatasetType(final ResolvedObject object, final String type) {
|
|
30 |
protected void setType(final ResolvedObject object, final String type) {
|
|
31 | 31 |
if (!StringUtils.isBlank(type)) { |
32 | 32 |
if (type.toLowerCase().contains("dataset")) { |
33 | 33 |
object.setType(ObjectType.dataset); |
34 |
return; |
|
35 |
} else if (type.toLowerCase().contains("publication")) { |
|
36 |
object.setType(ObjectType.publication); |
|
37 |
return; |
|
34 | 38 |
} else { |
35 |
|
|
36 |
log.error("Error on parsing record the type should be dataset or something like that found: " + type); |
|
37 |
return true; |
|
39 |
object.setType(ObjectType.unknown); |
|
38 | 40 |
} |
39 | 41 |
} |
40 |
return false; |
|
41 | 42 |
} |
42 | 43 |
|
43 | 44 |
} |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/parser/DMFDom4jResolverParser.java | ||
---|---|---|
68 | 68 |
|
69 | 69 |
final String type = document.valueOf("//*[local-name()='resource']/*[local-name()='resourceType']"); |
70 | 70 |
|
71 |
if (setDatasetType(object, type)) return null;
|
|
71 |
setType(object, type);
|
|
72 | 72 |
|
73 | 73 |
return object; |
74 | 74 |
} catch (Throwable e) { |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/parser/DMFResolverParser.java | ||
---|---|---|
100 | 100 |
} |
101 | 101 |
final String type = UtilityParser.getSingleValue(ap, vn, "//datacite:resourceType"); |
102 | 102 |
|
103 |
if (setDatasetType(parsedObject, type)) return null;
|
|
103 |
setType(parsedObject, type);
|
|
104 | 104 |
|
105 | 105 |
final List<String> dates = UtilityParser.getTextValue(ap, vn, "//datacite:dates/date"); |
106 | 106 |
|
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/OpenAireParser.java | ||
---|---|---|
1 |
package eu.dnetlib.resolver; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Arrays; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import com.ximpleware.AutoPilot; |
|
8 |
import com.ximpleware.VTDGen; |
|
9 |
import com.ximpleware.VTDNav; |
|
10 |
import eu.dnetlib.resolver.model.ResolvedObject; |
|
11 |
import eu.dnetlib.resolver.model.SubjectType; |
|
12 |
import eu.dnetlib.resolver.parser.AbstractResolverParser; |
|
13 |
import eu.dnetlib.resolver.parser.UtilityParser; |
|
14 |
import eu.dnetlib.resolver.parser.UtilityParser.Node; |
|
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 |
|
|
18 |
/** |
|
19 |
* Created by sandro on 10/3/16. |
|
20 |
*/ |
|
21 |
public class OpenAireParser extends AbstractResolverParser { |
|
22 |
|
|
23 |
private static final Log log = LogFactory.getLog(OpenAireParser.class); |
|
24 |
|
|
25 |
@Override |
|
26 |
public ResolvedObject parseObject(final String record) { |
|
27 |
try { |
|
28 |
final ResolvedObject currentObject = new ResolvedObject(); |
|
29 |
final VTDGen vg = new VTDGen(); |
|
30 |
vg.setDoc(record.getBytes()); |
|
31 |
vg.parse(true); |
|
32 |
|
|
33 |
final VTDNav vn = vg.getNav(); |
|
34 |
final AutoPilot ap = new AutoPilot(vn); |
|
35 |
|
|
36 |
ap.declareXPathNameSpace("oaf", "http://namespace.openaire.eu/oaf"); |
|
37 |
|
|
38 |
final List<Node> subjectNodes = |
|
39 |
UtilityParser.getTextValuesWithAttributes(ap, vn, "//oaf:result//subject", Arrays.asList("classname", "schemename")); |
|
40 |
|
|
41 |
//Setting subjects |
|
42 |
if (subjectNodes != null && subjectNodes.size() > 0) { |
|
43 |
final List<SubjectType> currentSubjects = new ArrayList<>(); |
|
44 |
|
|
45 |
subjectNodes.forEach(it -> |
|
46 |
currentSubjects.add(new SubjectType(it.getAttributes().get("schemename"), it.getTextValue())) |
|
47 |
); |
|
48 |
currentObject.setSubjects(currentSubjects); |
|
49 |
} |
|
50 |
|
|
51 |
//Setting Titles |
|
52 |
|
|
53 |
final List<String> titles = UtilityParser.getTextValue(ap, vn, "//oaf:result/title"); |
|
54 |
|
|
55 |
if (titles != null && titles.size() > 0) { |
|
56 |
|
|
57 |
currentObject.setTitles(titles); |
|
58 |
} |
|
59 |
|
|
60 |
//Setting authors |
|
61 |
final List<String> authorNodes = UtilityParser.getTextValue(ap, vn, "//oaf:result//fullname"); |
|
62 |
|
|
63 |
if (authorNodes != null && authorNodes.size() > 0) { |
|
64 |
currentObject.setAuthors(authorNodes); |
|
65 |
} |
|
66 |
|
|
67 |
//Setting descriptions |
|
68 |
final List<String> descriptions = UtilityParser.getTextValue(ap, vn, "//oaf:result//description"); |
|
69 |
|
|
70 |
if (descriptions != null && descriptions.size() > 0) { |
|
71 |
currentObject.setDescription(descriptions.get(0)); |
|
72 |
} |
|
73 |
|
|
74 |
//resulttype classid |
|
75 |
final List<Node> resutlTypes = UtilityParser.getTextValuesWithAttributes(ap, vn, "//oaf:result/resulttype", Arrays.asList("classid")); |
|
76 |
|
|
77 |
if (resutlTypes != null && resutlTypes.size() > 0) { |
|
78 |
final String type = resutlTypes.get(0).getAttributes().get("classid"); |
|
79 |
setType(currentObject, type); |
|
80 |
} |
|
81 |
|
|
82 |
return currentObject; |
|
83 |
} catch (Throwable e) { |
|
84 |
log.error("Error on parsing object ", e); |
|
85 |
return null; |
|
86 |
} |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
} |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/model/ObjectRelation.java | ||
---|---|---|
250 | 250 |
"Relation: \n\tId:%s \n\tSourcePid%s \n\tTargetPid:%s \n\tTargetPidType:%s \n\ttitle:%s \n\tCompletionStatus:%s \n\t Relation Semantic:%s \n\tProvenances:%s"; |
251 | 251 |
return String.format(format, this.getIDRelation(), this.getSourcePid(), this.getTargetPID() == null ? "" : this.getTargetPID(), |
252 | 252 |
this.getTargetType(), this.getTargetTitle(), this.getCompletionStatus(), this.getRelationSemantics(), |
253 |
relationProvenance);
|
|
253 |
this.getRelationProvenance());
|
|
254 | 254 |
} |
255 | 255 |
|
256 | 256 |
/** |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/model/serializer/ResolverSerializer.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.resolver.model.serializer; |
2 | 2 |
|
3 |
import java.io.ByteArrayOutputStream; |
|
4 |
|
|
5 |
import com.ximpleware.VTDGen; |
|
6 |
import com.ximpleware.VTDNav; |
|
7 |
import com.ximpleware.XMLModifier; |
|
8 |
import eu.dnetlib.resolver.model.ObjectType; |
|
3 | 9 |
import eu.dnetlib.resolver.model.ResolvedObject; |
10 |
import org.antlr.stringtemplate.StringTemplate; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
13 |
import org.springframework.beans.factory.annotation.Required; |
|
4 | 14 |
|
5 | 15 |
/** |
6 | 16 |
* Created by sandro on 9/21/16. |
7 | 17 |
*/ |
8 |
public interface ResolverSerializer {
|
|
18 |
public class ResolverSerializer {
|
|
9 | 19 |
|
10 |
/** |
|
11 |
* Serialize object in XML format |
|
12 |
* |
|
13 |
* @return the XML version |
|
14 |
*/ |
|
15 |
String serializeToXML(final ResolvedObject object); |
|
20 |
private static final Log log = LogFactory.getLog(ResolverSerializer.class); |
|
16 | 21 |
|
17 |
String serializeReplacingXML(final String xml, final ResolvedObject object);
|
|
22 |
private StringTemplate dmfTemplate;
|
|
18 | 23 |
|
24 |
private StringTemplate pmfTemplate; |
|
25 |
|
|
26 |
private StringTemplate scholixTemplate; |
|
27 |
|
|
28 |
|
|
29 |
public String serializeToXML(final ResolvedObject object) { |
|
30 |
|
|
31 |
if (object.getType() == null) |
|
32 |
object.setType(ObjectType.unknown); |
|
33 |
|
|
34 |
switch (object.getType()) { |
|
35 |
case publication: { |
|
36 |
pmfTemplate.removeAttribute("object"); |
|
37 |
pmfTemplate.setAttribute("object", object); |
|
38 |
return pmfTemplate.toString(); |
|
39 |
} |
|
40 |
case dataset: { |
|
41 |
dmfTemplate.removeAttribute("object"); |
|
42 |
dmfTemplate.setAttribute("object", object); |
|
43 |
return dmfTemplate.toString(); |
|
44 |
} |
|
45 |
case unknown: { |
|
46 |
scholixTemplate.removeAttribute("object"); |
|
47 |
scholixTemplate.setAttribute("object", object); |
|
48 |
return scholixTemplate.toString(); |
|
49 |
} |
|
50 |
} |
|
51 |
return null; |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
public String serializeReplacingXML(final String xml, final ResolvedObject object) { |
|
56 |
|
|
57 |
try { |
|
58 |
VTDGen vg = new VTDGen(); // Instantiate VTDGen |
|
59 |
XMLModifier xm = new XMLModifier(); //Instantiate XMLModifier |
|
60 |
|
|
61 |
vg.setDoc(xml.getBytes()); |
|
62 |
|
|
63 |
vg.parse(false); |
|
64 |
VTDNav vn = vg.getNav(); |
|
65 |
xm.bind(vn); |
|
66 |
|
|
67 |
// navigate to <metadata> |
|
68 |
if (vn.toElement(VTDNav.FC, "metadata")) { |
|
69 |
xm.insertBeforeElement("<metadata>" + serializeToXML(object) + "</metadata>"); |
|
70 |
xm.remove(); |
|
71 |
} |
|
72 |
final ByteArrayOutputStream bas = new ByteArrayOutputStream(); |
|
73 |
xm.output(bas); |
|
74 |
return new String(bas.toByteArray()); |
|
75 |
} catch (Throwable e) { |
|
76 |
if (log.isDebugEnabled()) { |
|
77 |
log.debug(String.format("Error on replacing xml: %s", xml)); |
|
78 |
} |
|
79 |
return null; |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
public StringTemplate getDmfTemplate() { |
|
84 |
return dmfTemplate; |
|
85 |
} |
|
86 |
|
|
87 |
@Required |
|
88 |
public void setDmfTemplate(final StringTemplate dmfTemplate) { |
|
89 |
this.dmfTemplate = dmfTemplate; |
|
90 |
} |
|
91 |
|
|
92 |
public StringTemplate getPmfTemplate() { |
|
93 |
return pmfTemplate; |
|
94 |
} |
|
95 |
|
|
96 |
@Required |
|
97 |
public void setPmfTemplate(final StringTemplate pmfTemplate) { |
|
98 |
this.pmfTemplate = pmfTemplate; |
|
99 |
} |
|
100 |
|
|
101 |
public StringTemplate getScholixTemplate() { |
|
102 |
return scholixTemplate; |
|
103 |
} |
|
104 |
|
|
105 |
@Required |
|
106 |
public void setScholixTemplate(final StringTemplate scholixTemplate) { |
|
107 |
this.scholixTemplate = scholixTemplate; |
|
108 |
} |
|
19 | 109 |
} |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/model/ResolvedObject.java | ||
---|---|---|
276 | 276 |
* @return the type |
277 | 277 |
*/ |
278 | 278 |
public ObjectType getType() { |
279 |
return type; |
|
279 |
return type == null ? ObjectType.unknown : type;
|
|
280 | 280 |
} |
281 | 281 |
|
282 | 282 |
/** |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/AbstractPIDResolver.java | ||
---|---|---|
140 | 140 |
protected String requestURL(final String url) { |
141 | 141 |
final CloseableHttpClient httpclient = HttpClients.createDefault(); |
142 | 142 |
try { |
143 |
|
|
143 | 144 |
HttpGet httpGet = new HttpGet(url); |
144 | 145 |
return httpclient.execute(httpGet, responseHandler); |
145 | 146 |
} catch (Throwable e) { |
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/OpenaireResolver.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.resolver; |
2 | 2 |
|
3 |
import java.net.URLEncoder; |
|
4 |
|
|
3 | 5 |
import com.google.common.collect.Lists; |
4 | 6 |
import com.google.gson.JsonArray; |
5 | 7 |
import com.google.gson.JsonElement; |
6 | 8 |
import com.google.gson.JsonObject; |
7 | 9 |
import com.google.gson.JsonParser; |
8 |
import eu.dnetlib.dli.parser.DLIRecordParser; |
|
9 | 10 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
10 | 11 |
import eu.dnetlib.resolver.model.ObjectProvenance; |
11 | 12 |
import eu.dnetlib.resolver.model.ResolvedObject; |
... | ... | |
15 | 16 |
|
16 | 17 |
public class OpenaireResolver extends AbstractPIDResolver { |
17 | 18 |
|
18 |
private final static String baseURL = "http://solr.openaire.eu:8983/solr/DMF-index-openaire_shard1_replica1/select?q=objidentifier:\"%s\"&wt=json"; |
|
19 |
private final static String templateURL = "objidentifier:\"%s\""; |
|
20 |
private final static String baseURL = "http://solr.openaire.eu:8983/solr/DMF-index-openaire_shard1_replica1/select?q=%s&wt=json"; |
|
19 | 21 |
|
20 | 22 |
private static final Log log = LogFactory.getLog(OpenaireResolver.class); // NOPMD by marko on 11/24/08 5:02 PM |
21 | 23 |
|
22 | 24 |
private ApplyXslt xsltMapper = new ApplyXslt(new ClassPathResource("eu/dnetlib/resolver/xslt/openaire2Dli.xslt")); |
23 |
; |
|
24 | 25 |
|
25 |
private DLIRecordParser parser = new DLIRecordParser();
|
|
26 |
private OpenAireParser parser = new OpenAireParser();
|
|
26 | 27 |
|
27 | 28 |
@Override |
28 | 29 |
protected boolean canResolvePid(final String pidType) { |
... | ... | |
32 | 33 |
@Override |
33 | 34 |
protected ResolvedObject resolve(final String pid, final String pidType) { |
34 | 35 |
try { |
35 |
ResolvedObject obj = parsingResponse(requestURL(String.format(baseURL, pid))); |
|
36 |
final String currentQuery = String.format(baseURL, URLEncoder.encode(String.format(templateURL, pid), "UTF-8")); |
|
37 |
ResolvedObject obj = parsingResponse(requestURL(currentQuery)); |
|
38 |
if (obj == null) |
|
39 |
return null; |
|
40 |
obj.setPidType(pidType); |
|
41 |
obj.setPid(pid); |
|
36 | 42 |
ObjectProvenance provenance = new ObjectProvenance("dli::openaireResolver", "resolved", "complete", null, null, true); |
37 | 43 |
obj.fixContribution(provenance); |
38 | 44 |
obj.setDatasourceProvenance(Lists.newArrayList(provenance)); |
... | ... | |
53 | 59 |
if (total == 0) return null; |
54 | 60 |
JsonArray hits = ((JsonObject) jobject.get("response")).get("docs").getAsJsonArray(); |
55 | 61 |
JsonElement s = ((JsonObject) hits.get(0)).get("__result").getAsJsonArray().get(0); |
56 |
String dlirecord = xsltMapper.apply(s.getAsString()); |
|
57 |
return parser.parseRecord(dlirecord); |
|
62 |
return parser.parseObject(s.getAsString()); |
|
58 | 63 |
} |
59 | 64 |
return null; |
60 | 65 |
|
modules/dnet-dli/trunk/src/main/java/eu/dnetlib/resolver/mdstore/plugin/RecordResolver.java | ||
---|---|---|
11 | 11 |
import eu.dnetlib.resolver.model.ObjectRelation; |
12 | 12 |
import eu.dnetlib.resolver.model.PID; |
13 | 13 |
import eu.dnetlib.resolver.model.ResolvedObject; |
14 |
import eu.dnetlib.resolver.model.serializer.DMFSerializer;
|
|
14 |
import eu.dnetlib.resolver.model.serializer.ResolverSerializer;
|
|
15 | 15 |
import eu.dnetlib.resolver.parser.DMFResolverParser; |
16 | 16 |
import org.antlr.stringtemplate.StringTemplate; |
17 | 17 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
24 | 24 |
public class RecordResolver implements Callable<Boolean> { |
25 | 25 |
|
26 | 26 |
private static final Log log = LogFactory.getLog(RecordResolver.class); |
27 |
private final DMFSerializer serializer = new DMFSerializer();
|
|
27 |
private final ResolverSerializer serializer = new ResolverSerializer();
|
|
28 | 28 |
private final DMFResolverParser parser = new DMFResolverParser(); |
29 | 29 |
private List<PIDResolver> pluginResolver; |
30 | 30 |
private BlockingQueue<DBObject> inputQueue; |
... | ... | |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
public void setTemplate(final StringTemplate template) { |
56 |
serializer.setTemplate(template); |
|
56 |
serializer.setDmfTemplate(template);
|
|
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
private String tryToResolveRelation(final PID currentPid) { |
modules/dnet-dli/trunk/src/main/resources/eu/dnetlib/dli/templates/ScholixXML.st | ||
---|---|---|
1 |
<scholix:link xmlns:scholix="http://www.scholix.org"> |
|
2 |
<assertion_info> |
|
3 |
$object.datasourceProvenance:{ |
|
4 |
<source>$it.datasource$</source> |
|
5 |
}$ |
|
6 |
$object.relations:{ |
|
7 |
<relationType scheme="datacite">$it.relationSemantics$</relationType> |
|
8 |
}$ |
|
9 |
</assertion_info> |
|
10 |
<source> |
|
11 |
<pid type="$object.pidType$">$object.pid$</pid> |
|
12 |
<type>$object.type$</type> |
|
13 |
</source> |
|
14 |
<target> |
|
15 |
$object.relations:{ |
|
16 |
<pid type="$it.targetPID.type$">$it.targetPID.id$</pid> |
|
17 |
<type>$it.targetType$</type> |
|
18 |
}$ |
|
19 |
</target> |
|
20 |
</scholix:link> |
modules/dnet-dli/trunk/src/main/resources/eu/dnetlib/dli/templates/PMFXML.st | ||
---|---|---|
1 |
<pmf:pid type ="$object.pidType$">$object.pid$</pmf:pid> |
|
2 |
$object.escapedXMLTitles:{ <dc:title>$it$</dc:title> }$ |
|
3 |
$object.authors:{<dc:creator> $it$ </dc:creator> }$ |
|
4 |
<dc:date>$object.date$</dc:date> |
|
5 |
<dc:description>$object.description$</dc:description> |
|
6 |
$object.subjects:{ <dc:subject>>$it.escapedTerm$</dc:subject>}$ |
|
7 |
<dc:type>$object.type$</dc:type> |
|
8 |
$object.datasourceProvenance:{<pmf:hostedBy id="$it.publisherId$" name="$it.publisher$"/> }$ |
|
9 |
$object.datasourceProvenance:{<pmf:collectedFrom id="$it.datasourceId$" name="$it.datasource$" mode="$it.provisionMode$" completionStatus="$it.completionStatus$">$it.datasourceId$</pmf:collectedFrom> }$ |
|
10 |
$object.relations:{ <pmf:relatedIdentifier type="$it.targetType$" pid="$it.targetPID.escapeXMLId$" pidType="$it.targetPID.type$"/> }$ |
modules/dnet-dli/trunk/src/main/resources/eu/dnetlib/dli/templates/DMFXML.st | ||
---|---|---|
12 | 12 |
<title>$it$</title> |
13 | 13 |
}$ |
14 | 14 |
</titles> |
15 |
|
|
16 | 15 |
$object.datasourceProvenance:{ |
17 |
<publisher>$it.publisher$</publisher> |
|
18 |
|
|
19 |
}$ |
|
16 |
<publisher>$it.publisher$</publisher> |
|
17 |
}$ |
|
20 | 18 |
<dates> |
21 | 19 |
<date dateType="Collected">$object.date$</date> |
22 | 20 |
</dates> |
23 | 21 |
<subjects> |
24 | 22 |
$object.subjects:{ |
25 | 23 |
<subject subjectScheme="$it.escapedScheme$">$it.escapedTerm$</subject> |
26 |
|
|
27 |
}$ |
|
24 |
}$ |
|
28 | 25 |
</subjects> |
29 | 26 |
<resourceType resourceTypeGeneral="$object.type$">$object.type$</resourceType> |
30 |
|
|
31 |
|
|
32 | 27 |
<relatedIdentifiers> |
33 | 28 |
$object.relations:{ |
34 | 29 |
<relatedIdentifier relatedIdentifierType="$it.targetPID.type$" relationType="$it.relationSemantics$">$it.targetPID.escapeXMLId$</relatedIdentifier> |
Also available in: Unified diff
implemented serializer