Skip to content

Commit

Permalink
added optional configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zygis0408 committed Dec 12, 2022
1 parent 6da12d6 commit fc76c9e
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 19 deletions.
100 changes: 98 additions & 2 deletions src/ExternalSearch.Providers.GoogleMaps/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ public static class Constants
public struct KeyName
{
public const string ApiToken = "apiToken";

public const string AcceptedEntityType = "acceptedEntityType";
public const string OrgNameKey = "orgNameKey";
public const string OrgAddressKey = "orgAddressKey";
public const string OrgZipCodeKey = "orgZipCodeKey";
public const string OrgStateKey = "orgStateKey";
public const string OrgCountryKey = "orgCountryKey";
public const string LocationAddressKey = "locationAddressKey";
public const string UserAddressKey = "userAddressKey";
public const string PersonAddressKey = "personAddressKey";
public const string PersonAddressCityKey = "personAddressCityKey";
public const string LatitudeKey = "latitudeKey";
public const string LongitudeKey = "longitudeKey";
}

public static string About { get; set; } = "Google Maps is a web mapping platform and consumer application offered by Google. It offers satellite imagery, aerial photography, street maps, 360° interactive panoramic views of streets, real-time traffic conditions, and route planning for traveling by foot, car, air and public transportation.";
Expand All @@ -31,7 +42,92 @@ public struct KeyName
type = "input",
isRequired = true,
name = KeyName.ApiToken
}
},
new Control()
{
displayName = "Accepted Entity Type",
type = "input",
isRequired = false,
name = KeyName.AcceptedEntityType
},
new Control()
{
displayName = "Organization Name vocab key",
type = "input",
isRequired = false,
name = KeyName.OrgNameKey
},
new Control()
{
displayName = "Organization Address vocab key",
type = "input",
isRequired = false,
name = KeyName.OrgAddressKey
},

new Control()
{
displayName = "Organization Zip vocab key",
type = "input",
isRequired = false,
name = KeyName.OrgZipCodeKey
},
new Control()
{
displayName = "Organization State vocab key",
type = "input",
isRequired = false,
name = KeyName.OrgStateKey
},
new Control()
{
displayName = "Organization Country vocab key",
type = "input",
isRequired = false,
name = KeyName.OrgCountryKey
},
new Control()
{
displayName = "Location Address vocab key",
type = "input",
isRequired = false,
name = KeyName.LocationAddressKey
},
new Control()
{
displayName = "User Address vocab key",
type = "input",
isRequired = false,
name = KeyName.UserAddressKey
},
new Control()
{
displayName = "Person Address vocab key",
type = "input",
isRequired = false,
name = KeyName.PersonAddressKey
},
new Control()
{
displayName = "Person Address City vocab key",
type = "input",
isRequired = false,
name = KeyName.PersonAddressCityKey
},
new Control()
{
displayName = "Latitude vocab key",
type = "input",
isRequired = false,
name = KeyName.LatitudeKey
},
new Control()
{
displayName = "Longitude vocab key",
type = "input",
isRequired = false,
name = KeyName.LongitudeKey
},
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,51 @@ public class GoogleMapsExternalSearchJobData : CrawlJobData
public GoogleMapsExternalSearchJobData(IDictionary<string, object> configuration)
{
ApiToken = GetValue<string>(configuration, Constants.KeyName.ApiToken);
AcceptedEntityType = GetValue<string>(configuration, Constants.KeyName.AcceptedEntityType);
OrgNameKey = GetValue<string>(configuration, Constants.KeyName.OrgNameKey);
OrgAddressKey = GetValue<string>(configuration, Constants.KeyName.OrgAddressKey);
OrgZipCodeKey = GetValue<string>(configuration, Constants.KeyName.OrgZipCodeKey);
OrgStateKey = GetValue<string>(configuration, Constants.KeyName.OrgStateKey);
OrgCountryKey = GetValue<string>(configuration, Constants.KeyName.OrgCountryKey);
LocationAddressKey = GetValue<string>(configuration, Constants.KeyName.LocationAddressKey);
UserAddressKey = GetValue<string>(configuration, Constants.KeyName.UserAddressKey);
PersonAddressKey = GetValue<string>(configuration, Constants.KeyName.PersonAddressKey);
PersonAddressCityKey = GetValue<string>(configuration, Constants.KeyName.PersonAddressCityKey);
LatitudeKey = GetValue<string>(configuration, Constants.KeyName.LatitudeKey);
LongitudeKey = GetValue<string>(configuration, Constants.KeyName.LongitudeKey);
}

public IDictionary<string, object> ToDictionary()
{
return new Dictionary<string, object> {
{ Constants.KeyName.ApiToken, ApiToken }
{ Constants.KeyName.ApiToken, ApiToken },
{ Constants.KeyName.AcceptedEntityType, AcceptedEntityType },
{ Constants.KeyName.OrgNameKey, OrgNameKey },
{ Constants.KeyName.OrgAddressKey, OrgAddressKey },
{ Constants.KeyName.OrgZipCodeKey, OrgZipCodeKey },
{ Constants.KeyName.OrgStateKey, OrgStateKey },
{ Constants.KeyName.OrgCountryKey, OrgCountryKey },
{ Constants.KeyName.LocationAddressKey, LocationAddressKey },
{ Constants.KeyName.UserAddressKey, UserAddressKey },
{ Constants.KeyName.PersonAddressKey, PersonAddressKey },
{ Constants.KeyName.PersonAddressCityKey, PersonAddressCityKey },
{ Constants.KeyName.LatitudeKey, LatitudeKey },
{ Constants.KeyName.LongitudeKey, LongitudeKey }
};
}

public string ApiToken { get; set; }
public string AcceptedEntityType { get; set; }
public string OrgNameKey { get; set; }
public string OrgAddressKey { get; set; }
public string OrgZipCodeKey { get; set; }
public string OrgStateKey { get; set; }
public string OrgCountryKey { get; set; }
public string LocationAddressKey { get; set; }
public string UserAddressKey { get; set; }
public string PersonAddressKey { get; set; }
public string PersonAddressCityKey { get; set; }
public string LatitudeKey { get; set; }
public string LongitudeKey { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
using CluedIn.Core.Data.Relational;
using CluedIn.Core.Providers;
using EntityType = CluedIn.Core.Data.EntityType;
using PdfSharpCore.Pdf.Content.Objects;
using CluedIn.Core.Data.Vocabularies;

namespace CluedIn.ExternalSearch.Providers.GoogleMaps
{
/// <summary>The googlemaps graph external search provider.</summary>
/// <seealso cref="CluedIn.ExternalSearch.ExternalSearchProviderBase" />
public class GoogleMapsExternalSearchProvider : ExternalSearchProviderBase, IExtendedEnricherMetadata, IConfigurableExternalSearchProvider
{
private static readonly EntityType[] AcceptedEntityTypes = { EntityType.Location, EntityType.Organization, EntityType.Location.Address, EntityType.Infrastructure.User, EntityType.Person };
private static EntityType[] AcceptedEntityTypes = { EntityType.Organization };

/**********************************************************************************************************
* CONSTRUCTORS
Expand Down Expand Up @@ -66,7 +68,21 @@ private GoogleMapsExternalSearchProvider(bool tokenProviderIsRequired)
/// <returns>The search queries.</returns>
public override IEnumerable<IExternalSearchQuery> BuildQueries(ExecutionContext context, IExternalSearchRequest request)
{
if (!this.Accepts(request.EntityMetaData.EntityType))
foreach (var externalSearchQuery in InternalBuildQueries(context, request))
{
yield return externalSearchQuery;
}
}
private IEnumerable<IExternalSearchQuery> InternalBuildQueries(ExecutionContext context, IExternalSearchRequest request, IDictionary<string, object> config = null)
{
if (config.TryGetValue(Constants.KeyName.AcceptedEntityType, out var customType) && !string.IsNullOrWhiteSpace(customType.ToString()))
{
if (!request.EntityMetaData.EntityType.Is(customType.ToString()))
{
yield break;
}
}
else if (!this.Accepts(request.EntityMetaData.EntityType))
yield break;

//var entityType = request.EntityMetaData.EntityType;
Expand All @@ -88,21 +104,18 @@ bool AddressFilter(string value)

var entityType = request.EntityMetaData.EntityType;

var organizationName = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInOrganization.OrganizationName, new HashSet<string>());
var organizationAddress = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInOrganization.Address, new HashSet<string>());
var organizationZip = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressZipCode, new HashSet<string>());
var organizationState = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressState, new HashSet<string>());
var organizationCountry = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName, new HashSet<string>());

var locationAddress = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInLocation.Address, new HashSet<string>());

var userAddress = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInUser.HomeAddress, new HashSet<string>());

var personAddress = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInPerson.HomeAddress, new HashSet<string>());
var personAddressCity = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInPerson.HomeAddressCity, new HashSet<string>());
var organizationName = GetValue(request, config, Constants.KeyName.OrgNameKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.OrganizationName);
var organizationAddress = GetValue(request, config, Constants.KeyName.OrgAddressKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.Address);
var organizationZip = GetValue(request, config, Constants.KeyName.OrgZipCodeKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressZipCode);
var organizationState = GetValue(request, config, Constants.KeyName.OrgStateKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);
var organizationCountry = GetValue(request, config, Constants.KeyName.OrgCountryKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);
var locationAddress = GetValue(request, config, Constants.KeyName.LocationAddressKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);
var userAddress = GetValue(request, config, Constants.KeyName.UserAddressKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);
var personAddress = GetValue(request, config, Constants.KeyName.PersonAddressKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);
var personAddressCity = GetValue(request, config, Constants.KeyName.PersonAddressCityKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);
var latitude = GetValue(request, config, Constants.KeyName.LatitudeKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);
var longitude = GetValue(request, config, Constants.KeyName.LongitudeKey, Core.Data.Vocabularies.Vocabularies.CluedInOrganization.AddressCountryName);

var latitude = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInLocation.AddressLattitude, new HashSet<string>());
var longitude = request.QueryParameters.GetValue(Core.Data.Vocabularies.Vocabularies.CluedInLocation.AddressLongitude, new HashSet<string>());

if (organizationName != null && organizationName.Count > 0
&& organizationAddress != null && organizationAddress.Count > 0
Expand Down Expand Up @@ -216,6 +229,21 @@ bool AddressFilter(string value)
}
}

private static HashSet<string> GetValue(IExternalSearchRequest request, IDictionary<string, object> config, string keyName, VocabularyKey defaultKey)
{
HashSet<string> value;
if (config.TryGetValue(keyName, out var customVocabKey) && !string.IsNullOrWhiteSpace(customVocabKey?.ToString()))
{
value = request.QueryParameters.GetValue<string, HashSet<string>>(customVocabKey.ToString(), new HashSet<string>());
}
else
{
value = request.QueryParameters.GetValue(defaultKey, new HashSet<string>());
}

return value;
}

/// <summary>Executes the search.</summary>
/// <param name="context">The context.</param>
/// <param name="query">The query.</param>
Expand Down Expand Up @@ -566,6 +594,12 @@ private void PopulateCompanyMetadata(IEntityMetadata metadata, IExternalSearchQu

public IEnumerable<EntityType> Accepts(IDictionary<string, object> config, IProvider provider)
{
var customTypes = config[Constants.KeyName.AcceptedEntityType].ToString();
if (string.IsNullOrWhiteSpace(customTypes))
{
AcceptedEntityTypes = new EntityType[] { config[Constants.KeyName.AcceptedEntityType].ToString() };
};

return AcceptedEntityTypes;
}

Expand Down

0 comments on commit fc76c9e

Please sign in to comment.