Project

General

Profile

« Previous | Next » 

Revision 57195

Added by Enrico Ottonello over 4 years ago

replaced with new saxonHE-SOLR-772 branch

View differences:

modules/dnet-data-provision-services/branches/saxonHE-SOLR772/README
1
Before starting SOLR 5 you need to run the following commands:
2

  
3
cd solr-X.Y.Z/server/solr
4
mkdir lib
5
cd lib
6
ln -s ../../../contrib/analysis-extras/lucene-libs/lucene-analyzers-icu-Z.X.Y.jar
7
ln -s ../../../contrib/analysis-extras/lib/icu4j-X.Y.jar
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>saxonHE-SOLR772-dnet-data-provision-services</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.wst.common.project.facet.core.builder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.jdt.core.javabuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.m2e.core.maven2Builder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
		<buildCommand>
24
			<name>org.eclipse.wst.validation.validationbuilder</name>
25
			<arguments>
26
			</arguments>
27
		</buildCommand>
28
	</buildSpec>
29
	<natures>
30
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
31
		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
32
		<nature>org.eclipse.jdt.core.javanature</nature>
33
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
34
		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
35
	</natures>
36
</projectDescription>
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/deploy.info
1
{
2
"type_source": "SVN",
3
"goal": "package -U source:jar",
4
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet50/modules/dnet-data-provision-services/branches/saxonHE-SOLR772",
5
"deploy_repository": "dnet5-snapshots",
6
"version": "5",
7
"mail": "alessia.bardi@isti.cnr.it",
8
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet5-snapshots",
9
"name": "dnet-data-provision-services-saxonHE-SOLR772"
10
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/resources/eu/dnetlib/test/profiles/OAIPublisherConfigurationDSResources/OAIPublisherConfigurationDSResourceType/OAIPublisherConfiguration-1.xml
1
<RESOURCE_PROFILE>
2
	<HEADER>
3
		<RESOURCE_IDENTIFIER value="OAIPublisherConfiguration" />
4
		<RESOURCE_TYPE value="OAIPublisherConfigurationDSResourceType" />
5
		<RESOURCE_KIND value="OAIPublisherConfigurationDSResources" />
6
		<RESOURCE_URI value="" />
7
		<DATE_OF_CREATION value="2001-12-31T12:00:00" />
8
	</HEADER>
9
	<BODY>
10
		    <CONFIGURATION>
11
            <OAISETS>
12
                <OAISET enabled="true">
13
                    <spec>OpenAccess</spec>
14
                    <name>Set of Open Access articles</name>
15
                    <description>Set of records having 'OPEN' license</description>
16
                    <query>(license = "OPEN")</query>
17
                </OAISET>
18
                <OAISET enabled="true">
19
                    <spec>ArticlesInNature</spec>
20
                    <name>Articles published by Nature</name>
21
                    <description>Set of articles published by Nature Publishing Group</description>
22
                    <query>(publisher = "Nature Publishing Group")</query>
23
                </OAISET>
24
                <OAISET enabled="true">
25
                    <spec>publications</spec>
26
                    <name>Publications</name>
27
                    <description>Set of all Publications</description>
28
                    <query>resulttypeid="publication"</query>
29
                </OAISET>
30
            </OAISETS>
31
            <METADATAFORMATS>
32
                <METADATAFORMAT exportable="true" metadataPrefix="oaf">
33
                    <NAMESPACE>http://namespace.openaire.eu/oaf</NAMESPACE>
34
                    <SCHEMA>http://www.openaire.eu/schema/0.1/oaf-0.1.xsd</SCHEMA>
35
                    <SOURCE_METADATA_FORMAT interpretation="openaire" layout="index" name="oaf"/>
36
                    <TRANSFORMATION_RULE/>
37
                    <BASE_QUERY>*</BASE_QUERY>
38
                </METADATAFORMAT>
39
                <METADATAFORMAT metadataPrefix="oai_dc" exportable="false">
40
                    <NAMESPACE>http://www.openarchives.org/OAI/2.0/oai_dc/</NAMESPACE>
41
                    <SCHEMA>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</SCHEMA>
42
                    <SOURCE_METADATA_FORMAT interpretation="openaire" layout="index" name="oaf"/>
43
                    <TRANSFORMATION_RULE>oaf2dc_VHJhbnNmb3JtYXRpb25SdWxlRFNSZXNvdXJjZXMvVHJhbnNmb3JtYXRpb25SdWxlRFNSZXNvdXJjZVR5cGU=</TRANSFORMATION_RULE>
44
                    <BASE_QUERY>oaftype="result"</BASE_QUERY>
45
                </METADATAFORMAT>
46
            </METADATAFORMATS>
47
            <INDICES>
48
                <INDEX name="objIdentifier" repeatable="false">
49
                    <SOURCE name="oaf" layout="index" interpretation="openaire" path="//*[local-name() ='objIdentifier']"/>
50
                </INDEX>
51
                <INDEX name="set" repeatable="true">
52
                    <SOURCE name="oaf" layout="index" interpretation="openaire" path="//collectedfrom/@name"/>
53
                </INDEX>
54
                <INDEX name="publisher" repeatable="true">
55
                    <SOURCE name="oaf" layout="index" interpretation="openaire" path="//publisher"/>
56
                </INDEX>
57
                <INDEX name="license" repeatable="false">
58
                    <SOURCE name="oaf" layout="index" interpretation="openaire" path="//bestlicense/@classid"/>
59
                </INDEX>
60
                <INDEX name="oaftype" repeatable="false">
61
                    <SOURCE name="oaf" layout="index" interpretation="openaire" path="local-name(//*[local-name()='entity']/*)"/>
62
                </INDEX>
63
                <INDEX name="resulttypeid" repeatable="false">
64
                    <SOURCE name="oaf" layout="index" interpretation="openaire" path="//*[local-name()='entity']/*[local-name()='result']/resulttype/@classid"/>
65
                </INDEX>
66
            </INDICES>
67
        </CONFIGURATION>
68
		<STATUS>
69
			<LAST_UPDATE value="2001-12-31T12:00:00" />
70
		</STATUS>
71
		<SECURITY_PARAMETERS>SECURITY_PARAMETERS</SECURITY_PARAMETERS>
72
	</BODY>
73
</RESOURCE_PROFILE>
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/resources/eu/dnetlib/index/solr/feed/record_noTargetFields.xml
1
<indexRecord xmlns:oai="http://www.openarchives.org/OAI/2.0/"
2
             xmlns:dri="http://www.driver-repository.eu/namespace/dri"
3
             xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:crm="http://www.cidoc-crm.org/cidoc-crm/"
4
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
5
             xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:foaf="http://xmlns.com/foaf/0.1/"
6
             xmlns:crmpe="http://parthenos.d4science.org/CRMext/CRMpe.rdfs/"
7
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
8
	<indexRecordIdentifier>http://parthenos.d4science.org/handle/Parthenos/REG/Actor/Huma-num%20Consortium</indexRecordIdentifier>
9
	<targetFields/>
10
	<result>
11
		<header>
12
			<dri:objIdentifier>http://parthenos.d4science.org/handle/Parthenos/REG/Actor/Huma-num%20Consortium</dri:objIdentifier>
13
			<dri:datasourcename/>
14
			<dri:dateOfCollection/>
15
			<dri:dateOfTransformation/>
16
		</header>
17
		<metadata>
18
			<rdf:RDF xmlns:ns2="http://parthenos.d4science.org/handle/Parthenos/REG/Service/"
19
			         xmlns:ns1="http://parthenos.d4science.org/CRMext/CRMpe.rdfs/">
20
				<rdf:Description
21
						rdf:about="http://parthenos.d4science.org/handle/Parthenos/REG/Service/Nakala">
22
					<ns1:PP2_provided_by>
23
						<ns1:PE25_RI_Consortium
24
								rdf:about="http://parthenos.d4science.org/handle/Parthenos/REG/Actor/Huma-num%20Consortium"
25
						/>
26
					</ns1:PP2_provided_by>
27
				</rdf:Description>
28
			</rdf:RDF>
29
		</metadata>
30
	</result>
31
</indexRecord>
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/resources/eu/dnetlib/oai/mongo/testRecord.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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:oaf="http://namespace.openaire.eu/oaf"
6
        xmlns:oai="http://www.openarchives.org/OAI/2.0/"
7
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
8
	<header xmlns="http://namespace.openaire.eu/">
9
		<dri:objIdentifier>od_______263::06235d139088d4b2ca45ace37c458a01</dri:objIdentifier>
10
		<dri:recordIdentifier>oai:DiVA.org:su-91808</dri:recordIdentifier>
11
		<dri:dateOfCollection/>
12
		<dri:mdFormat/>
13
		<dri:mdFormatInterpretation/>
14
		<dri:repositoryId>866c86e1-0e6a-4e12-b5ed-b7e0eb956381_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId>
15
		<dr:objectIdentifier/>
16
		<dr:dateOfCollection>2016-04-05T06:52:25.98Z</dr:dateOfCollection>
17
		<dr:dateOfTransformation>2016-04-05T06:53:01.394Z</dr:dateOfTransformation>
18
		<oaf:datasourceprefix>od_______263</oaf:datasourceprefix>
19
	</header>
20
	<metadata xmlns="http://namespace.openaire.eu/">
21
		<oaf:entity>
22
			<dc:title>Evaluation and Tuning of Model Trajectoriesand Spreading Rates in the Baltic Sea Using Surface Drifter Observations</dc:title>
23
			<dc:creator>Kjellsson, Joakim</dc:creator>
24
			<dc:creator>Döös, Kristofer</dc:creator>
25
			<dc:creator>Soomere, Tarmo</dc:creator>
26
			<dc:date>2013</dc:date>
27
			<dc:description>Results from experiments with surface drifters in the Baltic Sea in 2010–2011 are presented and discussed. In a first experiment, 12 SVP-B (Surface Velocity Program, with Barometer) drifters with a drogue at 12–18 m depth were deployed in the Baltic Sea. In a second experiment, shallow drifters extending to a depth of 1.5 m were deployed in the Gulf of Finland. Results from the SVP-B drifter experiment are compared to results from a regional ocean model and a trajectory code. Differences between the observed SVP-B drifters and simulated drifters are found for absolute dispersion (i.e., squared displacement from initial position) and relative dispersion (i.e., squared distance between two initially paired drifters). The former is somewhat underestimated since the simulated currents are neither as fast nor as variable as those observed. The latter is underestimated both due to the above-mentioned reasons and due to the resolution of the ocean model. For the shallower drifters, spreading in the upper 1–2 m of the Gulf of Finland is investigated. The spreading rate is about 200 m/day for separations &lt;0.5 km, 500 m/day for separations below 1 km and in the range of 0.5–3 km/day for separations in the range of 1–4 km. The spreading rate does not follow Richardson’s law. The initial spreading, up to a distance of about d=100–150 m, is governed by the power law d∼t 0.27 whereas for larger separations the distance increases as d∼t2.5.</dc:description>
28
			<dc:description>BalticWay</dc:description>
29
			<dc:format>application/pdf</dc:format>
30
			<dc:identifier>http://urn.kb.se/resolve?urn=urn:nbn:se:su:diva-91808</dc:identifier>
31
			<dc:language>eng</dc:language>
32
			<dc:publisher>Stockholms universitet, Meteorologiska institutionen (MISU)</dc:publisher>
33
			<dc:publisher>Stockholms universitet, Meteorologiska institutionen (MISU)</dc:publisher>
34
			<dc:publisher>Institute of Cybernetics, Tallinn University of Technology</dc:publisher>
35
			<dc:relation>Preventive Methods for Coastal Protection : Towards the Use of Ocean Dynamics for Pollution Control, p. 251-281</dc:relation>
36
			<dc:relation>info:eu-repo/grantAgreement/EC/FP7/217246</dc:relation>
37
			<dc:subject>surface drifters; rco; ocean model; trajectory;</dc:subject>
38
			<dc:type>Chapter in book</dc:type>
39
			<dc:type>info:eu-repo/semantics/bookPart</dc:type>
40
			<dc:type>text</dc:type>
41
			<dr:CobjCategory>0013</dr:CobjCategory>
42
			<dr:CobjIdentifier>urn:isbn:978-3-319-00440-2</dr:CobjIdentifier>
43
			<dr:CobjIdentifier>urn:isbn:978-3-319-00439-6</dr:CobjIdentifier>
44
			<dr:CobjIdentifier>doi:10.1007/978-3-319-00440-2_8</dr:CobjIdentifier>
45
			<oaf:dateAccepted>2013-01-01</oaf:dateAccepted>
46
			<oaf:projectid>corda_______::217246</oaf:projectid>
47
			<oaf:collectedDatasourceid>opendoar____::263</oaf:collectedDatasourceid>
48
			<oaf:accessrights>OPEN</oaf:accessrights>
49
			<oaf:hostedBy id="opendoar____::263" name="Publikationer från Stockholms universitet"/>
50
			<oaf:collectedFrom id="opendoar____::263" name="Publikationer från Stockholms universitet"/>
51
			<oaf:identifier identifierType="doi">10.1007/978-3-319-00440-2_8</oaf:identifier>
52
		</oaf:entity>
53
	</metadata>
54
	<about xmlns="http://namespace.openaire.eu/">
55
		<provenance xmlns="http://www.openarchives.org/OAI/2.0/provenance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/provenance http://www.openarchives.org/OAI/2.0/provenance.xsd">
56
			<originDescription altered="true" harvestDate="2016-04-05T06:52:25.98Z">
57
				<baseURL>http://su.diva-portal.org/dice/oai</baseURL>
58
				<identifier>oai:DiVA.org:su-91808</identifier>
59
				<datestamp>2013-07-05T10:47:00Z</datestamp>
60
				<metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>
61
			</originDescription>
62
		</provenance>
63
		<oaf:datainfo>
64
			<oaf:inferred>false</oaf:inferred>
65
			<oaf:deletedbyinference>false</oaf:deletedbyinference>
66
			<oaf:trust>0.9</oaf:trust>
67
			<oaf:inferenceprovenance/>
68
			<oaf:provenanceaction classid="sysimport:crosswalk:repository"
69
			                      classname="sysimport:crosswalk:repository"
70
			                      schemeid="dnet:provenanceActions" schemename="dnet:provenanceActions"/>
71
		</oaf:datainfo>
72
	</about>
73
</record>
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/resources/log4j.properties
1
org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
2

  
3
log4j.rootLogger=WARN, CONSOLE
4
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
5
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
6
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
7

  
8
log4j.logger.eu.dnetlib=DEBUG
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/oai/PublisherMiscTest.java
1
package eu.dnetlib.oai;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertFalse;
5

  
6
import java.text.Normalizer;
7

  
8
import org.apache.commons.lang3.StringEscapeUtils;
9
import org.junit.Test;
10

  
11
public class PublisherMiscTest {
12

  
13
	@Test
14
	public void test() {
15
		final String id = "NonavCreation.filmportal.de/DIF_NonAVCreation_EUROPA_TM & © Aardman Animations, LTD";
16
		final String newId = StringEscapeUtils.escapeXml11(id);
17
		assertEquals("NonavCreation.filmportal.de/DIF_NonAVCreation_EUROPA_TM &amp; © Aardman Animations, LTD", newId);
18
		assertFalse(id.equals(newId));
19
	}
20

  
21
	@Test
22
	public void test2() {
23
		// Hochschulschriftenserver - Universit&#228;t Frankfurt am Main
24
		String s = "Publikationenserver der Georg-August-Universit&#228;t G&#246;ttingen";
25
		System.out.println("String to normalize: " + s);
26
		s = StringEscapeUtils.unescapeXml(s);
27
		System.out.println("unescaped: " + s);
28
		s = Normalizer.normalize(s, Normalizer.Form.NFD);
29
		System.out.println("normalized: " + s);
30
		// remove tilde, dots... over letters
31
		s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}&&[^-_]]", "");
32
		// change punctuation into an underscore
33
		s = s.replaceAll("[\\p{Punct}&&[^-_]]", "_");
34
		// remove all non-word charcheters
35
		s = s.replaceAll("[\\W&&[^-_]]", "");
36
		System.out.println("Converted setSpec to: " + s);
37
	}
38

  
39
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/oai/sets/MongoSetCollectionTest.java
1
package eu.dnetlib.oai.sets;
2

  
3
import static org.junit.Assert.assertEquals;
4

  
5
import org.junit.Before;
6
import org.junit.Test;
7

  
8
import eu.dnetlib.oai.sets.MongoSetCollection;
9

  
10
public class MongoSetCollectionTest {
11

  
12
	private MongoSetCollection mongoSetCollection;
13
	private final String strangeSet = "Наукові журнали Національного Авіаційного Університету";
14

  
15
	@Before
16
	public void setup() {
17
		this.mongoSetCollection = new MongoSetCollection();
18
	}
19

  
20
	@Test
21
	public void test() {
22
		final String normalised = this.mongoSetCollection.normalizeSetSpec(this.strangeSet);
23
		assertEquals(MongoSetCollection.DEFAULT_SET, normalised);
24
	}
25

  
26
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/oai/mongo/MongoPublisherStoreTest.java
1
/**
2
 *
3
 */
4
package eu.dnetlib.oai.mongo;
5

  
6
import java.io.IOException;
7

  
8
import org.bson.types.Binary;
9
import org.junit.Assert;
10
import org.junit.Test;
11

  
12
/**
13
 * @author sandro
14
 *
15
 */
16
public class MongoPublisherStoreTest {
17

  
18
	/**
19
	 * Test method for {@link eu.dnetlib.oai.mongo.MongoPublisherStore#createCompressRecord(java.lang.String)}.
20
	 * 
21
	 * @throws IOException
22
	 */
23
	@Test
24
	public void testCreateCompressRecord() throws IOException {
25

  
26
		final MongoPublisherStore store = new MongoPublisherStore();
27
		final RecordInfoGenerator gen = new RecordInfoGenerator();
28
		final StringBuffer buffer = new StringBuffer();
29
		final String input = " CIAO MONDO DA SANDRO!";
30

  
31
		for (int i = 0; i < 10000; i++) {
32
			buffer.append(input);
33
		}
34
		final Binary data = store.createCompressRecord(buffer.toString());
35
		Assert.assertEquals(buffer.toString(), gen.decompressRecord(data.getData()));
36

  
37
	}
38

  
39
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/oai/mongo/MetadataExtractorTest.java
1
package eu.dnetlib.oai.mongo;
2

  
3
import java.io.StringReader;
4

  
5
import org.apache.commons.io.IOUtils;
6
import org.dom4j.Document;
7
import org.dom4j.io.SAXReader;
8
import org.junit.After;
9
import org.junit.Before;
10
import org.junit.Test;
11
import org.springframework.core.io.ClassPathResource;
12

  
13
/**
14
 * MetadataExtractor Tester.
15
 *
16
 * @author alessia
17
 * @version 1.0
18
 * @since
19
 *
20
 *        <pre>
21
 * Apr 6, 2016
22
 *        </pre>
23
 */
24
public class MetadataExtractorTest {
25

  
26
	final MetadataExtractor extractor = new MetadataExtractor();
27
	final SAXReader reader = new SAXReader();
28
	private Document doc;
29
	private final String filePath = "/eu/dnetlib/oai/mongo/testRecord.xml";
30

  
31
	@Before
32
	public void before() throws Exception {
33
		final String testRecord = IOUtils.toString(new ClassPathResource(this.filePath).getInputStream());
34
		this.doc = this.reader.read(new StringReader(testRecord));
35
	}
36

  
37
	@After
38
	public void after() throws Exception {}
39

  
40
	/**
41
	 * Method: evaluate(final Document xmlDoc)
42
	 */
43
	@Test
44
	public void testEvaluate() throws Exception {
45
		final long timeStart = System.currentTimeMillis();
46
		final String metadata = this.extractor.apply(this.doc);
47
		final long timeEnd = System.currentTimeMillis();
48
		System.out.println("Got metadata in ms " + (timeEnd - timeStart));
49
		System.out.println(metadata);
50
	}
51

  
52
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/oai/mongo/ProvenanceExtractorTest.java
1
package eu.dnetlib.oai.mongo;
2

  
3
import java.io.StringReader;
4

  
5
import org.apache.commons.io.IOUtils;
6
import org.dom4j.Document;
7
import org.dom4j.io.SAXReader;
8
import org.junit.After;
9
import org.junit.Before;
10
import org.junit.Test;
11
import org.springframework.core.io.ClassPathResource;
12

  
13
/**
14
 * ProvenanceExtractor Tester.
15
 *
16
 * @author <Authors name>
17
 * @version 1.0
18
 * @since
19
 * 
20
 *        <pre>
21
 * Apr 6, 2016
22
 *        </pre>
23
 */
24
public class ProvenanceExtractorTest {
25

  
26
	final ProvenanceExtractor extractor = new ProvenanceExtractor();
27
	final SAXReader reader = new SAXReader();
28
	private Document doc;
29
	private final String filePath = "/eu/dnetlib/oai/mongo/testRecord.xml";
30

  
31
	@Before
32
	public void before() throws Exception {
33
		final String testRecord = IOUtils.toString(new ClassPathResource(this.filePath).getInputStream());
34
		this.doc = this.reader.read(new StringReader(testRecord));
35
	}
36

  
37
	@After
38
	public void after() throws Exception {}
39

  
40
	/**
41
	 * Method: evaluate(final Document xmlDoc)
42
	 */
43
	@Test
44
	public void testEvaluate() throws Exception {
45
		final long timeStart = System.currentTimeMillis();
46
		final String prov = this.extractor.apply(this.doc);
47
		final long timeEnd = System.currentTimeMillis();
48
		System.out.println("Got provenance in ms " + (timeEnd - timeStart));
49
		System.out.println(prov);
50
	}
51

  
52
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/oai/mongo/RecordInfoGeneratorTest.java
1
package eu.dnetlib.oai.mongo;
2

  
3
import java.io.IOException;
4
import java.util.zip.ZipEntry;
5
import java.util.zip.ZipOutputStream;
6

  
7
import org.apache.commons.io.IOUtils;
8
import org.apache.commons.io.output.ByteArrayOutputStream;
9
import org.bson.types.Binary;
10
import org.junit.Before;
11
import org.junit.Test;
12
import org.springframework.core.io.ClassPathResource;
13

  
14
import eu.dnetlib.oai.conf.OAIConfigurationReader;
15

  
16
/**
17
 * RecordInfoGenerator Tester.
18
 *
19
 * @author <Authors name>
20
 * @version 1.0
21
 * @since
22
 * 
23
 *        <pre>
24
 * Apr 6, 2016
25
 *        </pre>
26
 */
27
public class RecordInfoGeneratorTest {
28

  
29
	private final RecordInfoGenerator gen = new RecordInfoGenerator();
30
	private final String filePath = "/eu/dnetlib/oai/mongo/testRecord.xml";
31
	private Binary binaryXML;
32

  
33
	@Before
34
	public void before() throws Exception {
35
		final String testRecord = IOUtils.toString(new ClassPathResource(this.filePath).getInputStream());
36
		this.binaryXML = createCompressRecord(testRecord);
37
	}
38

  
39
	/**
40
	 * Method: decompressRecord(final byte[] input)
41
	 */
42
	@Test
43
	public void testDecompressRecord() throws Exception {
44
		final long timeStart = System.currentTimeMillis();
45
		final String record = this.gen.decompressRecord(this.binaryXML.getData());
46
		final long timeEnd = System.currentTimeMillis();
47
		System.out.println("Decompressed record in ms " + (timeEnd - timeStart));
48
		System.out.println(record);
49
	}
50

  
51
	private Binary createCompressRecord(final String record) throws IOException {
52
		final ByteArrayOutputStream os = new ByteArrayOutputStream();
53
		final ZipOutputStream zos = new ZipOutputStream(os);
54
		final ZipEntry entry = new ZipEntry(OAIConfigurationReader.BODY_FIELD);
55
		zos.putNextEntry(entry);
56
		zos.write(record.getBytes());
57
		zos.closeEntry();
58
		// zos.flush();
59
		zos.close();
60
		return new Binary(os.toByteArray());
61
	}
62

  
63
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/cql/lucene/CqlTranslatorImplTest.java
1
package eu.dnetlib.cql.lucene;
2

  
3
import java.io.IOException;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7

  
8
import com.google.common.collect.BiMap;
9
import com.google.common.collect.HashBiMap;
10
import com.google.common.collect.Lists;
11
import com.google.common.collect.Maps;
12
import eu.dnetlib.cql.CqlTranslator;
13
import eu.dnetlib.cql.CqlTranslatorImpl;
14
import eu.dnetlib.cql.CqlUtils;
15
import eu.dnetlib.cql.parse.*;
16
import org.junit.Before;
17
import org.junit.Test;
18
import org.z3950.zing.cql.CQLNode;
19
import org.z3950.zing.cql.CQLParseException;
20
import org.z3950.zing.cql.CQLParser;
21

  
22
import static org.junit.Assert.assertEquals;
23
import static org.junit.Assert.assertNotNull;
24

  
25
/**
26
 * Created by alessia on 18/01/17.
27
 */
28
public class CqlTranslatorImplTest {
29

  
30
	private CqlTranslator translator;
31

  
32
	private Map<String, String> weights;
33

  
34
	@Before
35
	public void setUp() {
36
		translator = new CqlTranslatorImpl();
37

  
38
		weights = Maps.newHashMap();
39
		weights.put("title", "2");
40
		weights.put("ugo", "1.5");
41
		weights.put("tag", "3");
42
	}
43

  
44
	@Test
45
	public void testToSolr_0() throws Exception {
46

  
47
		String cqlQuery = "\"a b x\" and r and \"eng/ita\" or f any \"pippo pluto\" and \"con: duepunti\" not (d < 5 and d > 10)";
48
		String luceneQuery = translator.toLucene(cqlQuery);
49

  
50
		printQuery(cqlQuery, luceneQuery);
51
	}
52

  
53
	@Test
54
	public void testToSolr_00() throws Exception {
55

  
56
		String cqlQuery = "resultdupid exact datacite____::b49fd4e3386d82df348a120cfe43516b OR objidentifier exact datacite____::b49fd4e3386d82df348a120cfe43516b";
57
		String luceneQuery = translator.toLucene(cqlQuery);
58

  
59
		printQuery(cqlQuery, luceneQuery);
60
	}
61

  
62
	@Test
63
	public void testToSolr_1() throws Exception {
64

  
65
		String cqlQuery = "publicationdate =/within \"2000-01-01 2010-01-01\"";
66
		String luceneQuery = translator.toLucene(cqlQuery);
67

  
68
		printQuery(cqlQuery, luceneQuery);
69
	}
70

  
71
	@Test
72
	public void testToSolr_2() throws Exception {
73
		String query = "(_all=faust AND _all=pippo) AND _all<>cinegiornale";
74
		Node node = new AndNode(new AndNode(new TermNode("_all", Relation.EQUAL, "faust"), new TermNode("_all", Relation.EQUAL, "pippo")), new TermNode("_all",
75
				Relation.NOT, "cinegiornale"));
76

  
77
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
78

  
79
		printQuery(query, parsed.asLucene());
80
		System.out.println("NODE:   " + node.toLucene());
81
		System.out.println("NODE:   " + node.toString());
82
		assertEquals(node.toLucene(), parsed.asLucene());
83
	}
84

  
85
	@Test
86
	public void testToSolr_3() throws Exception {
87
		String query = "_all all faust";
88
		Node node = new TermNode("_all", Relation.ALL, "faust");
89
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
90
		printQuery(query, parsed.asLucene());
91
		assertEquals(node.toLucene(), parsed.asLucene());
92

  
93
		query = "__all all \"caracas roma\"";
94

  
95
		parsed = translator.getTranslatedQuery(query);
96
		printQuery(query, parsed.asLucene());
97

  
98
		query = "__all all caracas roma";
99
		parsed = translator.getTranslatedQuery(query);
100
		printQuery(query, parsed.asLucene());
101

  
102
		query = "__all any caracas roma";
103
		parsed = translator.getTranslatedQuery(query);
104
		printQuery(query, parsed.asLucene());
105

  
106
		query = "__all any \"caracas roma\"";
107
		parsed = translator.getTranslatedQuery(query);
108
		printQuery(query, parsed.asLucene());
109

  
110
		query = "__all exact caracas roma";
111
		parsed = translator.getTranslatedQuery(query);
112
		printQuery(query, parsed.asLucene());
113
	}
114

  
115
	@Test
116
	public void testToSolr_4() throws Exception {
117

  
118
		String cqlQuery = "publicationdate =/within \"2000-01-01 2010-01-01\" and title = \"ddd\" and y < 2010 or y <= 2010 or y > 2010 or y >= 2010";
119
		String luceneQuery = translator.toLucene(cqlQuery);
120

  
121
		printQuery(cqlQuery, luceneQuery);
122
	}
123

  
124
	@Test
125
	public void testToSolr_5() throws Exception {
126

  
127
		String cqlQuery = "publicationdate within \"2000-01-01 2010-01-01\"";
128
		String luceneQuery = translator.toLucene(cqlQuery);
129

  
130
		printQuery(cqlQuery, luceneQuery);
131
	}
132

  
133
	@Test
134
	public void testToSolr_6() throws Exception {
135

  
136
		String cqlQuery = "cat sortBy title/sort.descending";
137
		final TranslatedQuery tr = translator.getTranslatedQuery(cqlQuery);
138
		printQuery(cqlQuery, tr.asLucene());
139
		System.out.println(tr.getOptions());
140

  
141
	}
142

  
143
	@Test
144
	public void testToSolr_7() throws Exception {
145

  
146
		String cqlQuery = "title exact true sortBy title/sort.ascending";
147
		CQLNode parsed = new CQLParser().parse(cqlQuery);
148

  
149
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
150

  
151
		assertNotNull(luceneQuery.getOptions().getSort().getField());
152
		assertNotNull(luceneQuery.getOptions().getSort().getMode());
153

  
154
		assertEquals("title", luceneQuery.getOptions().getSort().getField());
155
		assertEquals(SortOperation.Mode.asc, luceneQuery.getOptions().getSort().getMode());
156

  
157
		System.out.println("LUCENE: " + luceneQuery.asLucene() + " OPTIONS:" + luceneQuery.getOptions().getSort().getField() + " "
158
				+ luceneQuery.getOptions().getSort().getMode());
159

  
160
		printQuery(cqlQuery, luceneQuery.asLucene());
161
	}
162

  
163
	@Test
164
	public void testToSolr_8() throws Exception {
165

  
166
		String cqlQuery = "__all all \"caracas - roma\"";
167
		CQLNode parsed = new CQLParser().parse(cqlQuery);
168
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
169

  
170
		printQuery(cqlQuery, luceneQuery.asLucene());
171
	}
172

  
173
	@Test
174
	public void testToSolr_9() throws Exception {
175

  
176
		String cqlQuery = "__all all \"caracas roma\"";
177
		CQLNode parsed = new CQLParser().parse(cqlQuery);
178
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
179

  
180
		printQuery(cqlQuery, luceneQuery.asLucene());
181

  
182
		cqlQuery = "__all all caracas roma";
183
		parsed = new CQLParser().parse(cqlQuery);
184
		luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
185

  
186
		printQuery(cqlQuery, luceneQuery.asLucene());
187

  
188
		cqlQuery = "__all any caracas roma";
189
		parsed = new CQLParser().parse(cqlQuery);
190
		luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
191

  
192
		printQuery(cqlQuery, luceneQuery.asLucene());
193

  
194
		cqlQuery = "__all any \"caracas roma\"";
195
		parsed = new CQLParser().parse(cqlQuery);
196
		luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
197

  
198
		printQuery(cqlQuery, luceneQuery.asLucene());
199

  
200
		cqlQuery = "__all exact caracas roma";
201
		parsed = new CQLParser().parse(cqlQuery);
202
		luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
203

  
204
		printQuery(cqlQuery, luceneQuery.asLucene());
205
	}
206

  
207
	@Test
208
	public void testToSolr_10() throws Exception {
209

  
210
		String cqlQuery = "__all all \"caracas - ro*\"";
211
		CQLNode parsed = new CQLParser().parse(cqlQuery);
212

  
213
		Map<String, List<String>> cqlOptions = Maps.newHashMap();
214
		BiMap<String, String> aliases = HashBiMap.create();
215

  
216
		cqlOptions.put("wildcard", Lists.newArrayList("true"));
217
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap(), cqlOptions, aliases,
218
				new HashMap<String, String>());
219
		printQuery(cqlQuery, luceneQuery.asLucene());
220

  
221
		cqlOptions = Maps.newHashMap();
222
		luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap(), cqlOptions, aliases, new HashMap<String, String>());
223

  
224
		printQuery(cqlQuery, luceneQuery.asLucene());
225
	}
226

  
227
	@Test
228
	public void testToSolr_11() throws Exception {
229

  
230
		String cqlQuery = "__all <> \"kreutz\" and __all <> \"austria\"";
231
		CQLNode parsed = new CQLParser().parse(cqlQuery);
232
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
233

  
234
		printQuery(cqlQuery, luceneQuery.asLucene());
235
	}
236

  
237
	@Test
238
	public void testToSolr_12() throws Exception {
239

  
240
		String cqlQuery = "__all <> \"kreutz\" and __all <> \"austria\" or __all <> \"italia\" and __dsid exact \"wwwww\"";
241
		CQLNode parsed = new CQLParser().parse(cqlQuery);
242
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
243

  
244
		printQuery(cqlQuery, luceneQuery.asLucene());
245
	}
246

  
247
	@Test
248
	public void testToSolr_13() throws Exception {
249

  
250
		String cqlQuery = "__all = faust and __all <> cinegiornale";
251

  
252
		CQLNode parsed = new CQLParser().parse(cqlQuery);
253
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
254

  
255
		printQuery(cqlQuery, luceneQuery.asLucene());
256
	}
257

  
258
	@Test
259
	public void testToSolr_14() throws Exception {
260

  
261
		String cqlQuery = "__all <> cinegiornale and __all = faust";
262

  
263
		CQLNode parsed = new CQLParser().parse(cqlQuery);
264
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
265

  
266
		printQuery(cqlQuery, luceneQuery.asLucene());
267
	}
268

  
269
	@Test
270
	public void testToSolr_15() throws Exception {
271

  
272
		String cqlQuery = "(asdasd or asfgqwr) and textual";
273

  
274
		CQLNode parsed = new CQLParser().parse(cqlQuery);
275
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
276

  
277
		printQuery(cqlQuery, luceneQuery.asLucene());
278
	}
279

  
280
	@Test
281
	public void testToSolr_16() throws Exception {
282

  
283
		String cqlQuery = "title = kreutz and subject any \"austria italy\" or tag = pippo and blabla";
284
		CQLNode parsed = new CQLParser().parse(cqlQuery);
285

  
286
		Map<String, List<String>> options = Maps.newHashMap();
287
		BiMap<String, String> aliases = HashBiMap.create();
288
		IdentityCqlValueTransformerMap map = new IdentityCqlValueTransformerMap();
289

  
290
		CQLNode expand = CqlUtils.expand(parsed, weights.keySet());
291

  
292
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(expand, map, options, aliases, weights);
293

  
294
		printQuery(cqlQuery, luceneQuery.asLucene());
295
	}
296

  
297
	@Test
298
	public void testToSolr_17() throws Exception {
299

  
300
		String cqlQuery = "a = 1 and b = 2 or c = 3 and blabla";
301
		CQLNode parsed = new CQLParser().parse(cqlQuery);
302

  
303
		Map<String, List<String>> options = Maps.newHashMap();
304
		BiMap<String, String> aliases = HashBiMap.create();
305
		IdentityCqlValueTransformerMap map = new IdentityCqlValueTransformerMap();
306

  
307
		Map<String, String> w = Maps.newHashMap();
308
		w.put("a", "2");
309
		w.put("c", "1.5");
310

  
311
		CQLNode expand = CqlUtils.expand(parsed, w.keySet());
312

  
313
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(expand, map, options, aliases, w);
314

  
315
		printQuery(cqlQuery, luceneQuery.asLucene());
316
	}
317

  
318
	@Test
319
	public void testToSolr_18() throws Exception {
320

  
321
		String cqlQuery = "a exact 1";
322
		CQLNode parsed = new CQLParser().parse(cqlQuery);
323

  
324
		Map<String, List<String>> options = Maps.newHashMap();
325
		BiMap<String, String> aliases = HashBiMap.create();
326
		aliases.put("a", "b");
327

  
328
		IdentityCqlValueTransformerMap map = new IdentityCqlValueTransformerMap();
329

  
330
		Map<String, String> w = Maps.newHashMap();
331

  
332
		CQLNode expand = CqlUtils.expand(parsed, w.keySet());
333

  
334
		TranslatedQuery luceneQuery = translator.getTranslatedQuery(expand, map, options, aliases, w);
335

  
336
		printQuery(cqlQuery, luceneQuery.asLucene());
337
	}
338

  
339
	@Test
340
	public void testToSolr_19() throws Exception {
341
		String query = "_all<>faust";
342
		Node node = new TermNode("_all", Relation.NOT, "faust");
343

  
344
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
345

  
346
		printQuery(query, parsed.asLucene());
347
		assertEquals(node.toLucene(), parsed.asLucene());
348

  
349
		query = "_all <> faust nozze";
350
		// node = new TermNode("_all", Relation.NOT, "faust nozze");
351
		parsed = translator.getTranslatedQuery(query);
352
		printQuery(query, parsed.asLucene());
353

  
354
	}
355

  
356
	@Test
357
	public void testToSolr_20() throws Exception {
358

  
359
		String query = "(title = ESTUDIO and title = abierto) not (title = mediante)";
360

  
361
		Node node = new NotNode(new AndNode(new TermNode("title", Relation.EQUAL, "ESTUDIO"), new TermNode("title", Relation.EQUAL, "abierto")), new TermNode(
362
				"title", Relation.EQUAL, "mediante"));
363

  
364
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
365

  
366
		printQuery(query, parsed.asLucene());
367
		assertEquals(node.toLucene(), parsed.asLucene());
368
	}
369

  
370
	@Test
371
	public void testToSolr_21() throws Exception {
372

  
373
		String query = "(title = ESTUDIO and title = abierto) not (title = mediante or title = verde)";
374

  
375
		Node node = new NotNode(new AndNode(new TermNode("title", Relation.EQUAL, "ESTUDIO"), new TermNode("title", Relation.EQUAL, "abierto")), new OrNode(
376
				new TermNode("title", Relation.EQUAL, "mediante"), new TermNode("title", Relation.EQUAL, "verde")));
377

  
378
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
379

  
380
		printQuery(query, parsed.asLucene());
381
		assertEquals(node.toLucene(), parsed.asLucene());
382
	}
383

  
384
	@Test
385
	public void testToSolr_22() throws Exception {
386
		String query = " and itemtype = *";
387
		// Node node = new TermNode("itemtype", Relation.EQUAL, "*");
388

  
389
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
390

  
391
		printQuery(query, parsed.asLucene());
392

  
393
		query = " AND itemtype = *";
394
		parsed = translator.getTranslatedQuery(query);
395
		printQuery(query, parsed.asLucene());
396

  
397
		Map<String, List<String>> cqlOptions = Maps.newHashMap();
398
		BiMap<String, String> aliases = HashBiMap.create();
399

  
400
		cqlOptions.put("wildcard", Lists.newArrayList("true"));
401

  
402
		query = "AND itemtype = vid* borat";
403
		parsed = translator.getTranslatedQuery(query, cqlOptions);
404
		printQuery(query, parsed.asLucene());
405

  
406
		// + - && || ! ( ) { } [ ] ^ " ~ * ? : \
407
		query = " AND f = * vid* bo?ra bo+ra bo-ra bo&ra bo!ra bo]ra bo^ra bo*ra";// bo|ra bo(ra bo)ra bo{ra bo}ra
408
		// bo\"ra bo~ra bo:ra bo\\ra";
409

  
410
		CQLNode cqlNode = new CQLParser().parse(query);
411
		parsed = translator.getTranslatedQuery(cqlNode, new IdentityCqlValueTransformerMap(), cqlOptions, aliases, new HashMap<String, String>());
412
		printQuery(query, parsed.asLucene());
413

  
414
		parsed = translator.getTranslatedQuery(query, cqlOptions);
415
		printQuery(query, parsed.asLucene());
416

  
417
		parsed = translator.getTranslatedQuery(query);
418
		printQuery(query, parsed.asLucene());
419
	}
420

  
421
	@Test
422
	public void testToSolr_23() throws Exception {
423

  
424
		String query = "_all = cat sortBy title/sort.descending";
425
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
426

  
427
		Node node = new TermNode("_all", Relation.EQUAL, "cat");
428

  
429
		printQuery(query, parsed.asLucene());
430
		assertEquals(node.toLucene(), parsed.asLucene());
431

  
432
		assertNotNull(parsed.getOptions().getSort().getField());
433
		assertNotNull(parsed.getOptions().getSort().getMode());
434

  
435
		assertEquals("title", parsed.getOptions().getSort().getField());
436
		assertEquals(SortOperation.Mode.desc, parsed.getOptions().getSort().getMode());
437
	}
438

  
439
	@Test
440
	public void testToSolr_24() throws Exception {
441

  
442
		String query = "invalid exact true sortBy title/sort.ascending";
443

  
444
		// Node node = new TermNode("invalid", Relation.EXACT, "true");
445

  
446
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
447

  
448
		printQuery(query, parsed.asLucene());
449

  
450
		assertNotNull(parsed.getOptions().getSort().getField());
451
		assertNotNull(parsed.getOptions().getSort().getMode());
452

  
453
		assertEquals("title", parsed.getOptions().getSort().getField());
454
		assertEquals(SortOperation.Mode.asc, parsed.getOptions().getSort().getMode());
455
	}
456

  
457
	@Test
458
	public void testToSolr_25() throws Exception {
459

  
460
		// String query = "deleted all true and __dsid all xxxxxxxxxxx";
461

  
462
		// ciao (+a +b +c)
463
		String query = "ciao or (_all all \"a b c\")";
464
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
465
		printQuery(query, parsed.asLucene());
466

  
467
		query = "(__all = ciao) or (__all all \"a b c\")";
468
		parsed = translator.getTranslatedQuery(query);
469
		printQuery(query, parsed.asLucene());
470

  
471
		query = "a and b";
472
		parsed = translator.getTranslatedQuery(query);
473
		printQuery(query, parsed.asLucene());
474
		query = "field=a and field=b";
475
		parsed = translator.getTranslatedQuery(query);
476
		printQuery(query, parsed.asLucene());
477

  
478
		query = "a or b";
479
		parsed = translator.getTranslatedQuery(query);
480
		printQuery(query, parsed.asLucene());
481

  
482
		query = "field=a or field=b";
483
		parsed = translator.getTranslatedQuery(query);
484
		printQuery(query, parsed.asLucene());
485

  
486
		query = "field all a or field all b";
487
		parsed = translator.getTranslatedQuery(query);
488
		printQuery(query, parsed.asLucene());
489
	}
490

  
491
	@Test
492
	public void testToSolr_26() throws Exception {
493

  
494
		String query = "publicationdate =/within \"2000-01-01 2010-01-01\"";
495
		Node node = new TermNode("publicationdate", Relation.WITHIN, "2000-01-01 2010-01-01");
496

  
497
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
498

  
499
		printQuery(query, parsed.asLucene());
500
		assertEquals(node.toLucene(), parsed.asLucene());
501
	}
502

  
503
	@Test
504
	public void testToSolr_27() throws Exception {
505

  
506
		String query = "((((publicationdate =/within \"2000-01-01 2010-01-01\" and title = \"ddd\") and y < 2010) or y <= 2010) or y > 2010) or y >= 2010";
507
		Node node = new OrNode(new OrNode(new OrNode(new AndNode(new AndNode(new TermNode("publicationdate", Relation.WITHIN, "2000-01-01 2010-01-01"),
508
				new TermNode("title", Relation.EQUAL, "ddd")), new TermNode("y", Relation.LT, "2010")), new TermNode("y", Relation.LTE, "2010")), new TermNode(
509
				"y", Relation.GT, "2010")), new TermNode("y", Relation.GTE, "2010"));
510

  
511
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
512

  
513
		printQuery(query, parsed.asLucene());
514
		assertEquals(node.toLucene(), parsed.asLucene());
515
	}
516

  
517
	@Test
518
	public void testToSolr_28() throws Exception {
519

  
520
		String query = "publicationdate =/within \"2000-01-01 2010-01-01\" and (title = \"ddd\" and (y < 2010 or (y <= 2010 or (y > 2010 or y >= 2010))))";
521

  
522
		Node node = new AndNode(new TermNode("publicationdate", Relation.WITHIN, "2000-01-01 2010-01-01"), new AndNode(new TermNode("title", Relation.EQUAL,
523
				"ddd"), new OrNode(new TermNode("y", Relation.LT, "2010"), new OrNode(new TermNode("y", Relation.LTE, "2010"), new OrNode(new TermNode("y",
524
				Relation.GT, "2010"), new TermNode("y", Relation.GTE, "2010"))))));
525

  
526
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
527

  
528
		printQuery(query, parsed.asLucene());
529
		assertEquals(node.toLucene(), parsed.asLucene());
530
	}
531

  
532
	@Test
533
	public void testToSolr_29() throws Exception {
534

  
535
		String query = "dateaccepted =/within \"1900-01-01 2000-01-01\" and dateaccepted >= 2010-01-01";
536

  
537
		Node node = new AndNode(new TermNode("dateaccepted", Relation.WITHIN, "1900-01-01 2000-01-01"),
538
				new TermNode("dateaccepted", Relation.GTE, "2010-01-01"));
539

  
540
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
541

  
542
		printQuery(query, parsed.asLucene());
543
		assertEquals(node.toLucene(), parsed.asLucene());
544

  
545
		query = "dateaccepted =/within \"1900-01-01 2000-01-01\" and dateaccepted > 2010-01-01";
546

  
547
		node = new AndNode(new TermNode("dateaccepted", Relation.WITHIN, "1900-01-01 2000-01-01"), new TermNode("dateaccepted", Relation.GT, "2010-01-01"));
548

  
549
		parsed = translator.getTranslatedQuery(query);
550

  
551
		printQuery(query, parsed.asLucene());
552
		assertEquals(node.toLucene(), parsed.asLucene());
553
	}
554

  
555
	@Test
556
	public void testToSolr_30() throws Exception {
557

  
558
		String query = "a = 1 and b = 2 and c = 3";
559
		Node node = new AndNode(new AndNode(new TermNode("a", Relation.EQUAL, "1"), new TermNode("b", Relation.EQUAL, "2")), new TermNode("c", Relation.EQUAL,
560
				"3"));
561

  
562
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
563

  
564
		printQuery(query, parsed.asLucene());
565
		assertEquals(node.toLucene(), parsed.asLucene());
566
	}
567

  
568
	@Test
569
	public void testToSolr_31() throws Exception {
570

  
571
		String query = "a = \"pippo pluto\" and b = 2 and c = 3";
572
		Node node = new AndNode(new AndNode(new TermNode("a", Relation.EQUAL, "pippo pluto"), new TermNode("b", Relation.EQUAL, "2")), new TermNode("c",
573
				Relation.EQUAL, "3"));
574

  
575
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
576

  
577
		printQuery(query, parsed.asLucene());
578
		assertEquals(node.toLucene(), parsed.asLucene());
579
	}
580

  
581
	@Test
582
	public void testToSolr_32() throws Exception {
583

  
584
		String query = "__all all \"caracas - ro*\"";
585

  
586
		TranslatedQuery parsed = translator.getTranslatedQuery(query);
587
		printQuery(query, parsed.asLucene());
588

  
589
		Map<String, List<String>> cqlOptions = Maps.newHashMap();
590
		cqlOptions.put("wildcard", Lists.newArrayList("true"));
591

  
592
		parsed = translator.getTranslatedQuery(query, cqlOptions);
593
		printQuery(query, parsed.asLucene());
594

  
595
	}
596

  
597
	@Test
598
	public void testToSolr_33() throws Exception {
599
		String query1 = "query=(deletedbyinference = false) AND (((oaftype exact project) and (test)) and (fundinglevel0_id exact corda_______::FP7))";
600
		printQuery(query1, translator.getTranslatedQuery(query1).asLucene());
601

  
602
		String query2 = "query=(((deletedbyinference = false) AND (oaftype exact project)) and (test)) and (fundinglevel0_id exact corda_______::FP7)";
603
		printQuery(query2, translator.getTranslatedQuery(query2).asLucene());
604

  
605
		String query3 = "(deletedbyinference = false) AND (((oaftype exact project) and (test)) and (fundinglevel0_id exact corda_______::FP7))";
606
		printQuery(query3, translator.getTranslatedQuery(query1).asLucene());
607

  
608
		String query4 = "(((deletedbyinference = false) AND (oaftype exact project)) and (test)) and (fundinglevel0_id exact corda_______::FP7)";
609
		printQuery(query4, translator.getTranslatedQuery(query2).asLucene());
610
	}
611

  
612
	@Test
613
	public void testWildcard() throws CQLParseException, IOException {
614

  
615
		Map<String, List<String>> options = new HashMap<String, List<String>>();
616

  
617
		String cqlQuery = "__all = \"test?\"";
618
		String lucene = translator.toLucene(cqlQuery, options);
619
		printQuery(cqlQuery, lucene);
620

  
621
		options.put("wildcard", Lists.newArrayList("true"));
622

  
623
		cqlQuery = "__all = \"test?\"";
624
		lucene = translator.toLucene(cqlQuery, options);
625
		printQuery(cqlQuery, lucene);
626
	}
627

  
628
	@Test
629
	public void testWildcard_2() throws CQLParseException, IOException {
630

  
631
		Map<String, List<String>> options = new HashMap<String, List<String>>();
632

  
633
		String cqlQuery = "thumbnail=localhost*";
634
		String lucene = translator.toLucene(cqlQuery, options);
635
		printQuery(cqlQuery, lucene);
636

  
637
		options.put("wildcard", Lists.newArrayList("true"));
638

  
639
		lucene = translator.toLucene(cqlQuery, options);
640
		printQuery(cqlQuery, lucene);
641
	}
642

  
643
	@Test
644
	public void testDateQuery() throws CQLParseException, IOException {
645
		String cqlQuery = "(resultdateofacceptance <= \"2012-03-15\")";
646
		Map<String, List<String>> options = new HashMap<String, List<String>>();
647
		String lucene = translator.toLucene(cqlQuery, options);
648
		printQuery(cqlQuery, lucene);
649
	}
650

  
651
	@Test
652
	public void testFullISODateQuery() throws CQLParseException, IOException {
653
		String cqlQuery = "(resultdateofacceptance <= 2012-03-15T00:00:00Z)";
654
		Map<String, List<String>> options = new HashMap<String, List<String>>();
655
		String lucene = translator.toLucene(cqlQuery, options);
656
		printQuery(cqlQuery, lucene);
657
	}
658

  
659
	@Test
660
	public void testNonDateQuery() throws CQLParseException, IOException {
661
		String cqlQuery = "(resultdateofacceptance <= 2012.03.15T00:00:00Z)";
662
		Map<String, List<String>> options = new HashMap<String, List<String>>();
663
		String lucene = translator.toLucene(cqlQuery, options);
664
		printQuery(cqlQuery, lucene);
665
	}
666

  
667
	@Test
668
	public void testNonDateQuery2() throws CQLParseException, IOException {
669
		String cqlQuery = "(resultdateofacceptance <= ciao)";
670
		Map<String, List<String>> options = new HashMap<String, List<String>>();
671
		String lucene = translator.toLucene(cqlQuery, options);
672
		printQuery(cqlQuery, lucene);
673
	}
674

  
675
	@Test
676
	public void testDateWrong() throws Exception {
677

  
678
		String cqlQuery = "publicationdate =/within \"2000-01-01 2010.99.01\"";
679
		String luceneQuery = translator.toLucene(cqlQuery);
680

  
681
		printQuery(cqlQuery, luceneQuery);
682
	}
683

  
684
	@Test
685
	public void testToDate() throws Exception {
686

  
687
		String cqlQuery = "publicationdate =/within \"* 2000-01-01\"";
688
		String luceneQuery = translator.toLucene(cqlQuery);
689

  
690
		printQuery(cqlQuery, luceneQuery);
691
	}
692

  
693
	private void printQuery(final String cql, final String lucene) throws CQLParseException, IOException {
694
		System.out.println("CQL:    " + cql);
695
		// System.out.println("PARSED: " + new CQLParser().parse(cql).toCQL());
696
		System.out.println("LUCENE: " + lucene + "\n");
697

  
698
	}
699
}
modules/dnet-data-provision-services/branches/saxonHE-SOLR772/src/test/java/eu/dnetlib/cql/lucene/CqlUtilsTest.java
1
package eu.dnetlib.cql.lucene;
2

  
3
import java.util.ArrayList;
4
import java.util.HashSet;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.Map.Entry;
8

  
9
import com.google.common.collect.Lists;
10
import com.google.common.collect.Maps;
11
import eu.dnetlib.cql.CqlGroup;
12
import eu.dnetlib.cql.CqlUtils;
13
import org.junit.Before;
14
import org.junit.Test;
15
import org.z3950.zing.cql.CQLNode;
16

  
17
import static org.junit.Assert.assertTrue;
18

  
19
/**
20
 * Created by alessia on 18/01/17.
21
 */
22
public class CqlUtilsTest {
23
	private Map<String, String> weights;
24

  
25
	@Before
26
	public void setUp() {
27
		weights = Maps.newHashMap();
28
		weights.put("title", "2");
29
		weights.put("ugo", "1.5");
30
		weights.put("tag", "3");
31
	}
32

  
33
	@Test
34
	public void test_0() {
35
		String query = "tag = pluto";
36
		CQLNode res = CqlUtils.filter(query, Lists.newArrayList("tag"));
37
		assertTrue(res == null);
38
	}
39

  
40
	@Test
41
	public void test_filter_1() {
42
		String query = "creator = pippo";
43
		CQLNode res = CqlUtils.filter(query, Lists.newArrayList("tag"));
44
		assertTrue(res.toCQL().equals(query));
45
	}
46

  
47
	@Test
48
	public void test_filter_2() {
49
		String query = "creator = pippo and tag = pluto";
50
		CQLNode res = CqlUtils.filter(query, Lists.newArrayList("tag"));
51
		System.out.println(res.toCQL());
52
	}
53

  
54
	@Test
55
	public void test_filter_3() {
56
		String query = "creator = pippo and tag = pluto and title = pizza";
57
		CQLNode res = CqlUtils.filter(query, Lists.newArrayList("tag"));
58
		System.out.println(res.toCQL());
59
	}
60

  
61
	@Test
62
	public void test_filter_4() {
63
		String query = "creator = pippo or tag = pluto and title = pizza";
64
		CQLNode res = CqlUtils.filter(query, Lists.newArrayList("tag"));
65
		System.out.println(res.toCQL());
66
	}
67

  
68
	@Test
69
	public void test_filter_5() {
70
		String query = "creator = pippo and tag = pluto or title = pizza";
71
		CQLNode res = CqlUtils.filter(query, Lists.newArrayList("tag"));
72
		System.out.println(res.toCQL());
73
	}
74

  
75
	//////
76

  
77
	@Test
78
	public void test_group_0() {
79
		String query = "(>s=NAMESPACE s.test=800) and  creator = pippo and tag = pluto or title = pizza or title = pozzo";
80
		Map<String, CQLNode> res = CqlUtils.group(query, Lists.newArrayList("tag", "title"));
81
		print(query, res);
82
	}
83

  
84
	@Test
85
	public void test_group_01() {
86
		String query = "test and language exact \"fin\"";
87
		Map<String, CQLNode> res = CqlUtils.group(query, Lists.newArrayList("language", "repositorycountry"));
88
		print(query, res);
89
	}
90

  
91
	@Test
92
	public void test_group_1() {
93
		String query = "creator = pippo and tag = pluto or title = pizza and tag = roma";
94
		Map<String, CQLNode> res = CqlUtils.group(query, Lists.newArrayList("tag"));
95
		print(query, res);
96
	}
97

  
98
	@Test
99
	public void test_group_1_1() {
100
		String query = "creator = pippo and ((tag = pluto or title = pizza) and tag = roma)";
101
		Map<String, CQLNode> res = CqlUtils.group(query, Lists.newArrayList("tag"));
102
		print(query, res);
103
	}
104

  
105
	@Test
106
	public void test_group_2() {
107
		String query = "creator = pippo and tag = pluto or title = pizza and tag = roma";
108
		Map<String, CQLNode> res = CqlUtils.group(query, Lists.newArrayList("tag", "creator", "title"));
109
		print(query, res);
110
	}
111

  
112
	@Test
113
	public void test_group_3() {
114
		String query = "creator = pippo and tag = pluto or title = pizza and tag = roma";
115
		Map<String, CQLNode> res = CqlUtils.group(query, new ArrayList<String>());
116
		print(query, res);
117
	}
118

  
119
	@Test
120
	public void test_group_3_1() {
121
		String query = "creator = pippo or tag = roma";
122
		Map<String, CQLNode> res = CqlUtils.group(query, Lists.newArrayList("tag"));
123
		print(query, res);
124
	}
125

  
126
	@Test
127
	public void test_group_3_2() {
128
		String query = "tag = roma or blabla or bloblo";
129
		Map<String, CQLNode> res = CqlUtils.group(query, Lists.newArrayList(CqlGroup.defaultTerm));
130
		print(query, res);
131
	}
132

  
133
	////
134

  
135
	@Test
136
	public void test_group_4_1() {
137
		String query = "creator = pippo and tag = pluto or title = pizza and tag = roma";
138
		List<String> res = CqlUtils.listTerms(query, "tag");
139
		System.out.println("[query: " + query + "]");
140
		System.out.println(res);
141
	}
142

  
143
	@Test
144
	public void test_group_4_2() {
145
		String query = "tag = pippo";
146
		List<String> res = CqlUtils.listTerms(query, "tag");
147
		System.out.println("[query: " + query + "]");
148
		System.out.println(res);
149
	}
150

  
151
	@Test
152
	public void test_group_4_3() {
153
		String query = "creator = pippo and tag = pluto or title = pizza or tag = roma and blabla or bloblo";
154
		Map<String, CQLNode> res = CqlUtils.group(query, CqlUtils.listFields(query));
155
		print(query, res);
156
	}
157

  
158
	@Test
159
	public void test_expand_1() {
160
		String query = "tag = roma or blabla or bloblo";
161
		CQLNode res = CqlUtils.expand(query, weights.keySet());
162
		System.out.println("[query: " + query + "]");
163
		System.out.println(res.toCQL());
164
	}
165

  
166
	@Test
167
	public void test_expand_2() {
168
		String query = "blabla or bloblo";
169
		CQLNode res = CqlUtils.expand(query, weights.keySet());
170
		System.out.println("[query: " + query + "]");
171
		System.out.println(res.toCQL());
172
	}
173

  
174
	@Test
175
	public void test_expand_3() {
176
		String query = "blabla";
177
		CQLNode res = CqlUtils.expand(query, weights.keySet());
178
		System.out.println("[query: " + query + "]");
179
		System.out.println(res.toCQL());
180
	}
181

  
182
	@Test
183
	public void test_expand_4() {
184
		String query = "tag = roma or blabla or bloblo";
185
		CQLNode res = CqlUtils.expand(query, new HashSet<String>());
186
		System.out.println("[query: " + query + "]");
187
		System.out.println(res.toCQL());
188
	}
189

  
190
	////
191

  
192
	@Test
193
	public void test_list_fields_0() {
194
		String query = "pippo";
195
		List<String> res = CqlUtils.listFields(query);
196
		System.out.println("[query: " + query + "]");
197
		System.out.println(res);
198
	}
199

  
200
	@Test
201
	public void test_list_fields_1() {
202
		String query = "tag = pippo";
203
		List<String> res = CqlUtils.listFields(query);
204
		System.out.println("[query: " + query + "]");
205
		System.out.println(res);
206
	}
207

  
208
	///////////////////////
209
	private void print(String query, Map<String, CQLNode> res) {
210
		System.out.println("query: [" + query + "]");
211
		for (Entry<String, CQLNode> e : res.entrySet()) {
212
			System.out.println(e.getKey() + ": [" + e.getValue().toCQL() + "]");
213
		}
214
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff