unsupported-text-language exception in AlchemyAPI? - alchemyapi

I'm using AlchemyAPI "AlchemyAPI.TextGetTaxonomy(String)" method and it's returning exception: "unsupported-text-language". My input is: "factorial carrot".
Please advise where to set language ? My preferred language is "English".
Your response is highly appreciated.

Thanks Vlad for your help.
I'm doing REST calls and after testing and debugging, this issues is fixed finally.
If anyone facing same problem (using REST call) then just set:
data.append("&language=english");
in class:
com.alchemyapi.api.AlchemyAPI

Are you using an SDK or Rest calls?
If you are using the Java SDK, the following thread helped me out with the same type of problem, but for a different service: Github Issue 1
Basically it suggests to set the "language" paramater to "english".
params.put("language", "english");
I believe this can be adapted for any SDK or Rest Call.
I find it strange that this parameter is not specified in the documentation, nor in the Java SDK Constants, but it works.
UPDATE:
Apparently newer versions of the java SDK have a setLanguage()
method. Source Github Issue 2
Example:
final AlchemyLanguage service = new AlchemyLanguage();
service.setLanguage(LanguageSelection.ENGLISH); // <--
final Map<String, Object> params = new HashMap<String, Object>();
params.put(AlchemyLanguage.TEXT, "delete laboratory record");
final SAORelations relations = service.getRelations(params).execute();

Related

Swagger getting struck when returning Microsoft.Graph.User return type

I have a default .NET 6 WebAPI project generated by VisualStudio to which I have added Microsoft.Graph nuget package
Here is my program.cs
and finally my controller
When I run this project and try to test the Get endpoint, the swagger UI is getting struck and there is no error being thrown
If I change the return type to either dynamic or object, it works as expected. Maybe I overlooking something basic but I couldn't figure out this issue. Any help is appreciated.
You can speedup rendering for complex types like Microsoft.Graph.User by disabling syntax highlight.
app.UseSwaggerUI(config =>
{
config.ConfigObject.AdditionalItems["syntaxHighlight"] = new Dictionary<string, object>
{
["activated"] = false
};
});
With this setting UI gets stuck only for 10-15 seconds.

How to load plugins when updating to MvvmCross 6.4.2 from 5.6.2

I've been tasked with maintaining a Xamarin native project using MvvmCross 5.6.2. Not knowing exactly how to approach this, I've decided to update to one major version at a time (6 first, then 7 and 8). I'm not sure why I specifically have chosen 6.4.2, but it was maybe because this was the latest version of the majority of the plugins I was using on Nuget.
So far, the update has been a success and I have been able to fix all build errors. However, when running the application, I've been getting a null reference exception which I can't fully trace.
Based on the limited application output, I've been able to determine that the problem lies somewhere in my Android's setup.cs class (I think). I've been following Nick's .NET Travels advice on MvvmCross debugging. From viewing the MvvmCross 6.4.2. source and pasting in the following code in my own overrides:
public virtual void LoadPlugins(IMvxPluginManager pluginManager)
{
Type pluginAttribute = typeof(MvxPluginAttribute);
IEnumerable<Assembly> pluginAssemblies = GetPluginAssemblies();
foreach (Assembly item in pluginAssemblies)
{
IEnumerable<Type> enumerable = item.ExceptionSafeGetTypes();
foreach (Type item2 in enumerable)
{
if (TypeContainsPluginAttribute(item2))
{
pluginManager.EnsurePluginLoaded(item2);
}
}
}
bool TypeContainsPluginAttribute(Type type)
{
object[] customAttributes = type.GetCustomAttributes(pluginAttribute, inherit: false);
return ((customAttributes != null && customAttributes.Length != 0) ? 1 : 0) > (false ? 1 : 0);
}
}
public virtual IEnumerable<Assembly> GetPluginAssemblies()
{
string mvvmCrossAssemblyName = typeof(MvxPluginAttribute).Assembly.GetName().Name;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
var test = from asmb in assemblies.AsParallel()
where AssemblyReferencesMvvmCross(asmb, mvvmCrossAssemblyName)
select asmb;
return test;
}
I'm able to see that GetPluginAssemblies doesn't return any enumerable, and the LoadPlugins method then produces the NullReferenceException. But I can't see what this NullReference actually is.
I followed the upgrading from 5 to 6 guide https://www.mvvmcross.com/documentation/upgrading/upgrade-to-mvvmcross-60.
I looked at the MvvmCross 6 and 6.4.0 release pages:
https://www.mvvmcross.com/mvvmcross-6.0.0-release/
https://www.mvvmcross.com/mvvmcross-6.4.0-release/
And I followed Benjamin Mayrargue's guide: https://medium.com/#bigoudi/upgrading-from-mvvmcross-5-to-mvvmcross-6-7ded83ecb69d
But I have been unable to load my plugins (previously they were bootstraps, but most of the guides say these can be discarded now and that loading plugins is easier).
I also attempted the answer suggested in this question How to use an mvvmcross plugin such as the file plugin.
But to no avail.
So I am asking if anyone knows a good guide or how to use plugins in MvvmCross 6.4.2.
Thank you.
Plugins are just a way to register things in the IoC Container. This is done by MvvmCross during startup using the LoadPlugins method in your Setup file.
Most of the time it should just work. However, there are some caveats.
If the Linker has gone ahead and linked away some of the plugins code, you will have a bad time. What you can do about that is to hint the mono linker to not strip the code away.
Add a LinkerPleaseInclude class and add a Include method in it that looks something like:
new MvvmCross.Plugin.Color.Platforms.Ios.Plugin().Load();
You can do that for every plugin you may want to use.
If LoadPlugins doesn't find the entry Assembly, sometimes it also does not register the plugins. You can override LoadPlugins in your Setup class and just call EnsurePluginLoaded:
public override void LoadPlugins(IMvxPluginManager pluginManager)
{
base.LoadPlugins(pluginManager);
pluginManager.EnsurePluginLoaded<MvvmCross.Plugin.Color.Platforms.Ios.Plugin>();
}
I want to thank Cheesebaron for his plugin support. I think I've fixed my issue and as it turned out, I don't think there is a plugin issue after all (yet).
Thanks to Toolmakersteve also. His suggestion for using a try catch in the OnCreate of my overridden MvxSplashScreenAppCompatActivity surfaced an issue with setting a theme for this activity. In actuality, this class was initially a MvxSplashScreenActivity.
Reverting this line, I then started getting NullReferenceExceptions on specific lines, all relating to IoC and lazy construction of singletons. The class Mvx seemed to be throwing up this error. On a sort of hunch from previous experience with my updating, I removed the MvvmCross.Platform using statement and checked what suggestions Mvx had available to it. It suggested MvvmCross and MvvmCross.Platform, so I tried the former instead. Sure enough, this moved my execution further, throwing up more Null Reference Exceptions. I also encountered one instance of failing to resolve IMvxResourceLoader from MvvmCross.Platform.Platform. Switching that to MvvmCross.Base did the trick.
This was only a chance fix through a bit of guess work. #CheeseBaron, should I add this as a note to this bit of documentation https://www.mvvmcross.com/documentation/upgrading/upgrade-to-mvvmcross-60? As mentioned, I'm as far as 6.4.2 now, so I'm not certain this is the right place for it.
I've got a few bugs with embedded resources to fix now, but if I encounter any more that are relevant to my question, I'll list them here.

google cloud messaging push with parse and android client does not work

used those lines in android:
InstanceID instanceID = InstanceID.getInstance(this);
String token = null;
token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
got exception , token=null.
google.android.gms.iid.InstanceID.getToken(Unknown Source)
any suggestions?
checked that sender id is ok and api key. no clue.
thanks
I had this error as well. That was because I called instanceID.getToken in the main thread. The GCD guide says that: Do not call this method in the main thread; instead, use a service that extends IntentService.
Here there is a tutorial where is shown how create an IntentService where you can call instanceID.getToken. I hope this help.
thankx for the answer.
I did all the steps except the steps
sendRegistrationToServer(token);
....
since my token was null I was not able to procseed.
I had no problems with parse push service.
when I tried to replace it with gcm it did not work.
The issue is most definitely concerning your google-services.json file. Make sure that you have configured it correctly.
One of the reasons for this "unknown source" issue is a tampered file.

Anyone using Serilog.Extras.MSOwin

I was wondering if anyone has seen a demo/example of using the Serilog.Extras.MSOwin package with a web api project or a example/tutorial of using Serilog with a web api project.
Any help greatly appreciated,
Jim
I will take this as question as "How do I used Serilog.Extras.MSOwin?" and given it is currently a rather small library answer here.
This reflects the current library (1.4.102) and is subject to change in the future.
Serilog.Extras.MSOwin provides two things: a Microsoft.Owin.Logging.ILoggerFactory implementation to have OWIN's logging infrastructure write to Serilog (more details about logging in OWIN in this blog post) and Guid identifier (RequestId) for each web request to aid in associating logged events.
The Logging integration is done with the following:
IAppBuilder app = ...;
Serilog.ILogger logger = ...'
app.SetLoggerFactory( new Serilog.Extras.MSOwin.LoggerFactory( logger ) );
The request id functionality needs to be registered in the OWIN pipeline:
IAppBuilder app = ...;
app.UseSerilogRequestContext("RequestId");
You will want to register that very early in the pipeline because any logging occurring before that pipeline step will not have the request id available.
You also need will need to retrieve it from the LogContext using Enrich.FromLogContext() and add that property to what you write to your sinks. For example,
const string DefaultOutputTemplate =
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} ({RequestId}) {Message}{NewLine}{Exception}";
ILogger logger =
new LoggerConfiguration().Enrich.FromLogContext()
.WriteTo
.RollingFile(
"log.txt",
outputTemplate: DefaultOutputTemplate)
.CreateLogger();
Serilog.Extras.MSOwin was superseded by SerilogWeb.Owin (which has since also been discontinued.)

Getting "Object is read only" error when setting ClientCredentials in WCF

I have a proxy object generated by Visual Studio (client side) named ServerClient. I am attempting to set ClientCredentials.UserName.UserName/Password before opening up a new connection using this code:
InstanceContext context = new InstanceContext(this);
m_client = new ServerClient(context);
m_client.ClientCredentials.UserName.UserName = "Sample";
As soon as the code hits the UserName line it fails with an "Object is read-only" error. I know this can happen if the connection is already open or faulted, but at this point I haven't called context.Open() yet.
I have configured the Bindings (which uses netTcpBinding) to use Message as it's security mode, and MessageClientCredentialType is set to UserName.
Any ideas?
I noticed that after creating an instance of the proxy class for the service, I can set the Username and Password once without errors and do a successful call to my webservice. When I then try to set the Username and Password again on the existing instance (unnecessary of course) I get the 'Object is Read-Only' error you mentioned. Setting the values once per instance lifetime worked for me.
It appears that you can only access these properties pretty early in the instanciation cycle. If I override the constructor in the proxy class (ServerClient), I'm able to set these properties:
base.ClientCredentials.UserName.UserName = "Sample";
I'm beginning to appreciate the people who suggest not using the automatically built proxies provided by VS.
here is the solution:
using SysSvcmod = System.ServiceModel.Description;
SysSvcmod.ClientCredentials clientCredentials = new SysSvcmod.ClientCredentials();
clientCredentials.UserName.UserName = "user_name";
clientCredentials.UserName.Password = "pass_word";
m_client.ChannelFactory.Endpoint.Behaviors.RemoveAt(1);
m_client.ChannelFactory.Endpoint.Behaviors.Add(clientCredentials);
I have similar code that's passing UserName fine:
FooServiceClient client = new FooServiceClient("BasicHttpBinding_IFooService");
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "password";
Try creating the proxy with binding name in app.config.
The correct syntax is:
// Remove the ClientCredentials behavior.
client.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
// Add a custom client credentials instance to the behaviors collection.
client.ChannelFactory.Endpoint.Behaviors.Add(new MyClientCredentials());
http://msdn.microsoft.com/en-us/library/ms730868.aspx
It worked for me.
I was facing same problem, my code started working when I changed my code i.e. assigning values to Client credential immediately after initializing Client object.
here is the solution ,
ProductClient Manager = new ProductClient();
Manager.ClientCredentials.UserName.UserName = txtUserName.Text;
Manager.ClientCredentials.UserName.Password = txtPassword.Text;
This will not happen if the service reference is added through -> Add service reference ->Advanced->Add Web Reference-> Url/wsdl (local disk file).
I was facing this issue where I was trying to create a generic method to create a clients for different end points.
Here how I achieved this.
public static T CreateClient<T>(string url) where T : class
{
EndpointAddress endPoint = new EndpointAddress(url);
CustomBinding binding = CreateCustomBinding();
T client = (T)Activator.CreateInstance(typeof(T), new object[] { binding, endPoint });
SetClientCredentials(client);
return client;
}
public static void SetClientCredentials(dynamic obj)
{
obj.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
obj.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());
obj.ClientCredentials.UserName.UserName = "UserId";
obj.ClientCredentials.UserName.Password = "Password";
}
I think your problem might be related to the use of the InstanceContext. I thought that was only needed for duplex communication channels from the server side.
I admit I'm not sure about this, but I think in this case you are telling the client to use an existing instance context so it thinks there is already a running service and will not allow changes.
What is driving the use of InstanceContext?
If using a duplex client, when you instantiate it the DuplexChannelFactory within the DuplexClientBase that your client is derived from is initialized with existing credentials so it can open the callback channel, which is why the credentials would be read only.
I second Mike's question and also ask why are you using NetTcpBinding if you are not going to use its inherent transport level security? Perhaps an HTTP based binding would be a better fit? That would allow you to use certificate based security which I believe can be modified after instantiation (http://msdn.microsoft.com/en-us/library/ms576164.aspx).
A shot in the dark but does netTcpBinding allow username and password validation? Try using application layer (SOAP) security using a http binding
or you could just simply check the Credentials
if (client.ClientCredentials.ClientCertificate.Certificate == null || string.IsNullOrEmpty(client.ClientCredentials.ClientCertificate.Certificate.Thumbprint))
{
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindByThumbprint, ConfigurationManager.AppSettings.Get("CertificateThumbprint"));
}
In .NET 4.6 I couldn't remove the credentials using Fabienne's answer. Kept getting Compiler Error CS0308 in the Remove method. What worked for me was this:
Type endpointBehaviorType = serviceClient.ClientCredentials.GetType();
serviceClient.Endpoint.EndpointBehaviors.Remove(endpointBehaviorType);
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = userName;
clientCredentials.UserName.Password = password;
serviceClient.Endpoint.EndpointBehaviors.Add(clientCredentials);

Resources