How do I get the mlContect ITransformer - ml.net

The following code will load a saved model and will load 'mlModel' as part of that process.
var mlContext = new MLContext();
ITransformer mlModel = mlContext.Model.Load(MLNetModelPath, out var _);
return mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
However, If I have just an existing trained mlContext, how do I get the 'ITransformer' from that existing mlContext?

You can load it from a stream instead of file:
See this documentation

Related

M2Doc error <---Couldn't find the 'getText(EClassifier=Model)' service

I was using m2doc programmatically, and this is my code.
final URI templateURI = URI.createFileURI(templateName+"."+M2DocUtils.DOCX_EXTENSION_FILE);
final URI modelURI = URI.createFileURI(modelName);
// can be empty, if you are using a Generation use GenconfUtils.getOptions(generation)
final Map<String, String> options = new HashMap<>();
List<Exception> exceptions = new ArrayList<>();
final ResourceSet resourceSetForModels = M2DocUtils.createResourceSetForModels(exceptions , "key", new ResourceSetImpl(), options);
//resourceSetForModels.getResource(modelURI, true);
final Resource r = resourceSetForModels.getResource(modelURI, true);
System.out.println(r.getContents());
final EObject value = r.getContents().get(0);
// if you are using a Generation, use GenconfUtils.getQueryEnvironment(resourceSetForModels, generation)
final IQueryEnvironment queryEnvironment = M2DocUtils.getQueryEnvironment(resourceSetForModels, templateURI, options); // delegate to IServicesConfigurator
final IClassProvider classProvider = new ClassProvider(this.getClass().getClassLoader()); // use M2DocPlugin.getClassProvider() when running inside Eclipse
final Monitor monitor = new BasicMonitor.Printing(System.out);
try (DocumentTemplate template = M2DocUtils.parse(resourceSetForModels.getURIConverter(), templateURI, queryEnvironment, classProvider, monitor)) {
// validate
final ValidationMessageLevel validationLevel = M2DocUtils.validate(template, queryEnvironment, monitor);
if (validationLevel != ValidationMessageLevel.OK) {
final URI validationResulURI = URI.createFileURI(templateName+"-validation."+M2DocUtils.DOCX_EXTENSION_FILE); // some place to serialize the result of the validation
M2DocUtils.serializeValidatedDocumentTemplate(resourceSetForModels.getURIConverter(), template, validationResulURI);}
//generate
final Map<String, Object> variables = new HashMap<>(); // your variables and values
variables.put("self", value);
final URI outputURI = URI.createFileURI(templateName+"-result."+M2DocUtils.DOCX_EXTENSION_FILE); // some place to serialize the result of the generation
M2DocUtils.generate(template, queryEnvironment, variables, resourceSetForModels, outputURI, monitor);
}finally {
M2DocUtils.cleanResourceSetForModels("key", resourceSetForModels);
}
And when I ran the program, the validation file was created, and it shows lots of errors. The errors were like this: <---Couldn't find the 'getText(EClassifier=Model)' service. They appeared everywhere I used the service getText().
When I use the same template and the same uml file to generate document by using the m2doc plugin in eclipse, it went alright.
I wonder if my query environment setting was wrong.
Thank you if you can help me.
M2DocUtils.parse() initialize the IQueryEnvironment with services and nsURIs imported in the template. So you should not need to add anything.
If you are running inside Eclipse you should use:
final IClassProvider classProvider = M2DocPlugin.getClassProvider()
It should help loading your service Class (it use OSGi to load classes from bundles).
You can also check if any TemplateValidationMessage are present with more details:
DocumentTemplate.getBody().getValidationMessages()
At this point either the UML metamodel is not registered or it's your service Class (more likely).
You can register the UML EPackage and see if it helps:
queryEnvironment.registerEPackage(UMLPackage.eINSTANCE)
You can also try to register your service class:
final Set<IService> s = ServiceUtils.getServices(queryEnvironment, SomeServiceClass.class);
ServiceUtils.registerServices(queryEnvironment, s);

How do I get the Code Review Id in a custom section of the code review page?

I am writing a visual studio extension that has a section on the code review page. I would like access to the information about the rest of the code review page, specifically what code review is current on the page being displayed. I should be able to access the workitemId but so far I have not figured out how.
Edit
Using Cole's suggestion I have accessed the PageContent but I do not know what type I should cast the content to. Nor do I know when it will be available. I would like access both when I initialize my section, and later. Here is my code when I try to initialize the section:
public override object SectionContent
{
get
{
if (base.SectionContent == null)
{
var teamExplorerPage = this.GetService<ITeamExplorerPage>();
var pageContent = teamExplorerPage.PageContent;
this.model.CodeReviewId = pageContent;
base.SectionContent = new CodePlusTeamExplorerSectionView(this.ServiceProvider, this.model);
}
return base.SectionContent;
}
}
When I debug the code I see that a DataContext is available on the PageContent, but I do not know what type to cast the pageContent (orITeamExplorerPage) to, to gain access to it. Also the DataContext has a CodeReviewId property which seems like the value I need but it is null at this point of the Lifecycle. If I want to retrieve some additional data based on the CodeReviewId when/where is it available?
I am still trying to figure out how to get it earlier in the lifecycle of the page but from an event like a button click in the page I can retrieve the value using reflection. This seems like a bit of a hack, perhaps someone else has a better way, but here it is.
private void Button_Click(object sender, RoutedEventArgs e)
{
var teamExplorer = this.GetService<ITeamExplorer>();
var currentPage = teamExplorer.CurrentPage;
var currentContent = currentPage.PageContent;
Type type = currentContent.GetType();
PropertyInfo pi = type.GetProperty("DataContext");
var dataContext = pi.GetValue(currentContent);
Type contextTypetype = dataContext.GetType();
PropertyInfo contextTypePi = contextTypetype.GetProperty("CodeReviewId");
var codeReviewId = contextTypePi.GetValue(dataContext);
var context = new Dictionary<string, object>();
context.Add("WorkItemId", codeReviewId);
teamExplorer.NavigateToPage(new Guid(TeamExplorerPageIds.ViewCodeReview), context);
}

Rally Web Services API: How do I get the URL link of the user story? (getDetailUrl() method)

Please be patient and Do Not flag this as duplicate: Using the Rally REST API, how can I get the non-API (website) URL for a user story?
I want to be able to generate a link for the user story.
Something like this: https://rally1.rallydev.com/#/-/detail/userstory/*********
As opposed to this: https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/88502329352
The link will be integrated into another application for the managers to see the user story.
I did read about the getDetailUrl() method, but in my case I am creating the user stories by parsing email and linking that to a notification service in Slack.
I am aware of the formattedID and (_ref), but I would have to query for it again, and I am creating batches of userstories through a loop. I need the actual web site link to the user story.
Here is my sample code:
public void CreateUserStory(string workspace, string project, string userstoryName){
//authenticate with Rally
this.EnsureRallyIsAuthenticated();
//DynamicJsonObject for HierarchicalRequirement
DynamicJsonObject toCreate = new DynamicJsonObject();
toCreate[RallyConstant.WorkSpace] = workspace;
toCreate[RallyConstant.Project] = project;
toCreate[RallyConstant.Name] = userstoryName;
try
{
//Create the User Story Here
CreateResult createUserStory = _api.Create(RallyConstant.HierarchicalRequirement, toCreate);
Console.WriteLine("Created Userstory: " + "URL LINK GOES HERE");
}
catch (WebException e)
{
Console.WriteLine(e.Message);
}
}
We don't have a method in the .NET toolkit for doing this, but it's easy to create.
The format is this:
https://rally1.rallydev.com/#/detail/<type>/<objectid>
Just fill in the type (hierarchicalrequirement turns into userstory, but all the others are the same as the wsapi type) and the objectid from the object you just created.
var parameters = new NameValueCollection();
parameters["fetch"] = "FormattedID";
var toCreate = new DynamicJsonObject();
var createResult = restApi.create("hierarchicalrequirement", toCreate, parameters);
var type = Ref.getTypeFromRef(createResult.Reference);
var objectID = Ref.getOidFromRef(createResult.Reference);
var formattedID = createResult.Object["FormattedID"];
And you can specify fetch fields to be returned on the created object so you don't have to re-query for it.

facebook c# api, video getting uploaded but its PUBLIC

I am able to upload video from the code below. But the video isn't PRIVATE. I need video to be PRIVATE or in other words it should be SELF.
FacebookMediaObject mediaObject1 = new FacebookMediaObject
{
FileName = pbmFile.fullPath,
ContentType = Path.GetExtension(filePath)
};
byte[] fileBytes1 = System.IO.File.ReadAllBytes(filePath);
mediaObject1.SetValue(fileBytes1);
IDictionary<string, object> upload1 = new Dictionary<string, object>();
upload1.Add("image", mediaObject1);
staticGlobalConst.fbClient1.Post("/me/videos", upload1, staticGlobalConst.del1Video) as JsonObject
When I add the code below it throws exception
I tried adding parameter
upload1.Add("privacy", "SELF");
How can I upload a private video?
Thanks
Sujit
I solved it by adding below parameter
upload1.Add("privacy", "{\"value\":\"SELF\"}");
that is depends on what was your choice for " Visibility of app and posts: " option when the first time you authenticated with the app.
you can change it to : Public,Friends,Only Me , from your Account Settings>Apps and choose your application and change it .

creating thumbnail from a pdf in coldfusion cfscript

I'm trying to create a thumbnail from a pdf in coldfusion, but no thumbnail gets created and no exception is thrown.
(coldfusion 9)
my code:
var source = "A:\testfolder\test.pdf";
var destination = "A:\testfolder\";
createImageFromPdf(source, destination);
createImageFromPdf function:
public void function createImageFromPdf(required string source, required string destination,
numeric pages = 1, string resolution = "low",
numeric scale = 100, boolean overwrite = true){
var pdf = new pdf();
pdf.setSource(arguments.source);
pdf.thumbnail(pages = arguments.pages, resolution = arguments.resolution,
scale = arguments.scale, overwrite = arguments.overwrite);
}
After running this code, i don't receive errors or exceptions, but no image was generated in A:\testfolder\
I'm probably missing something obvious here, but can't find it.
Also no log records are created in application or exception log, pdf is not protected and I'm sure that the folder is writable.
All help is appreciated.
Thanks.
You just forgot to pass along the destination
pdf.thumbnail(destination=arguments.destination
, pages = arguments.pages
, resolution = arguments.resolution
, scale = arguments.scale
, overwrite = arguments.overwrite);