mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 14:48:49 +00:00
try to guess correct from and to locations
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@467 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
4300807b37
commit
d6e9cdfe1f
2 changed files with 38 additions and 5 deletions
|
@ -309,7 +309,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
if (addresses.isEmpty())
|
if (addresses.isEmpty())
|
||||||
{
|
{
|
||||||
return queryConnections(uri, page);
|
return queryConnections(uri, page, from, to);
|
||||||
}
|
}
|
||||||
else if (P_CHECK_FROM.matcher(page).find())
|
else if (P_CHECK_FROM.matcher(page).find())
|
||||||
{
|
{
|
||||||
|
@ -328,7 +328,21 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
|
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
|
||||||
{
|
{
|
||||||
final CharSequence page = ParserUtils.scrape(uri);
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
return queryConnections(uri, page);
|
return queryConnections(uri, page, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Pattern P_LOCATION_ADDRESS = Pattern.compile("\\d{5}.*?,.*");
|
||||||
|
|
||||||
|
private Location location(final String str, final Location originalLocation)
|
||||||
|
{
|
||||||
|
if (P_LOCATION_ADDRESS.matcher(str).matches())
|
||||||
|
return new Location(LocationType.ADDRESS, 0, null, str);
|
||||||
|
else if (originalLocation != null && str.equals(originalLocation.name))
|
||||||
|
return originalLocation;
|
||||||
|
else if (originalLocation != null && originalLocation.type == LocationType.ADDRESS && str.length() == 0)
|
||||||
|
return originalLocation;
|
||||||
|
else
|
||||||
|
return new Location(LocationType.ANY, 0, null, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern P_CONNECTIONS_HEAD = Pattern.compile(".*?" //
|
private static final Pattern P_CONNECTIONS_HEAD = Pattern.compile(".*?" //
|
||||||
|
@ -345,7 +359,8 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
+ "(?:\\d+ Umst\\.|([\\w\\d ]+)).*?" // line
|
+ "(?:\\d+ Umst\\.|([\\w\\d ]+)).*?" // line
|
||||||
, Pattern.DOTALL);
|
, Pattern.DOTALL);
|
||||||
|
|
||||||
private QueryConnectionsResult queryConnections(final String uri, final CharSequence page) throws IOException
|
private QueryConnectionsResult queryConnections(final String uri, final CharSequence page, final Location originalFrom, final Location originalTo)
|
||||||
|
throws IOException
|
||||||
{
|
{
|
||||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||||
if (mError.find())
|
if (mError.find())
|
||||||
|
@ -365,8 +380,8 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
final Matcher mHead = P_CONNECTIONS_HEAD.matcher(page);
|
final Matcher mHead = P_CONNECTIONS_HEAD.matcher(page);
|
||||||
if (mHead.matches())
|
if (mHead.matches())
|
||||||
{
|
{
|
||||||
final Location from = new Location(LocationType.ANY, 0, null, ParserUtils.resolveEntities(mHead.group(1)));
|
final Location from = location(ParserUtils.resolveEntities(mHead.group(1)), originalFrom);
|
||||||
final Location to = new Location(LocationType.ANY, 0, null, ParserUtils.resolveEntities(mHead.group(2)));
|
final Location to = location(ParserUtils.resolveEntities(mHead.group(2)), originalTo);
|
||||||
final Date currentDate = ParserUtils.parseDate(mHead.group(3));
|
final Date currentDate = ParserUtils.parseDate(mHead.group(3));
|
||||||
final String linkEarlier = mHead.group(4) != null ? BVG_BASE_URL + ParserUtils.resolveEntities(mHead.group(4)) : null;
|
final String linkEarlier = mHead.group(4) != null ? BVG_BASE_URL + ParserUtils.resolveEntities(mHead.group(4)) : null;
|
||||||
final String linkLater = mHead.group(5) != null ? BVG_BASE_URL + ParserUtils.resolveEntities(mHead.group(5)) : null;
|
final String linkLater = mHead.group(5) != null ? BVG_BASE_URL + ParserUtils.resolveEntities(mHead.group(5)) : null;
|
||||||
|
|
|
@ -17,13 +17,18 @@
|
||||||
|
|
||||||
package de.schildbach.pte.live;
|
package de.schildbach.pte.live;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import de.schildbach.pte.BvgProvider;
|
import de.schildbach.pte.BvgProvider;
|
||||||
|
import de.schildbach.pte.NetworkProvider.WalkSpeed;
|
||||||
|
import de.schildbach.pte.dto.Connection;
|
||||||
import de.schildbach.pte.dto.Location;
|
import de.schildbach.pte.dto.Location;
|
||||||
|
import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,6 +37,7 @@ import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
public class BvgProviderLiveTest
|
public class BvgProviderLiveTest
|
||||||
{
|
{
|
||||||
private BvgProvider provider = new BvgProvider();
|
private BvgProvider provider = new BvgProvider();
|
||||||
|
private static final String ALL_PRODUCTS = "IRSUTBFC";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void autocompleteIncomplete() throws Exception
|
public void autocompleteIncomplete() throws Exception
|
||||||
|
@ -62,4 +68,16 @@ public class BvgProviderLiveTest
|
||||||
final QueryDeparturesResult queryDepartures = provider.queryDepartures("309557", 0);
|
final QueryDeparturesResult queryDepartures = provider.queryDepartures("309557", 0);
|
||||||
System.out.println(queryDepartures.departures);
|
System.out.println(queryDepartures.departures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shortConnection() throws Exception
|
||||||
|
{
|
||||||
|
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 9056102, "Berlin", "Nollendorfplatz"),
|
||||||
|
null, new Location(LocationType.STATION, 9013103, "Berlin", "Prinzenstraße"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
||||||
|
System.out.println(result);
|
||||||
|
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
||||||
|
for (final Connection connection : result.connections)
|
||||||
|
provider.getConnectionDetails(connection.link);
|
||||||
|
System.out.println(moreResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue